2023-02-15 16:04:19 +01:00
package exerr
2023-07-24 10:42:39 +02:00
import (
"gogs.mikescher.com/BlackForestBytes/goext/langext"
)
2023-02-15 16:04:19 +01:00
type ErrorCategory struct { Category string }
var (
CatWrap = ErrorCategory { "Wrap" } // The error is simply wrapping another error (e.g. when a grpc call returns an error)
CatSystem = ErrorCategory { "System" } // An internal system error (e.g. connection to db failed)
CatUser = ErrorCategory { "User" } // The user (the API caller) did something wrong (e.g. he has no permissions to do this)
CatForeign = ErrorCategory { "Foreign" } // A foreign error that some component threw (e.g. an unknown mongodb error), happens if we call Wrap(..) on an non-bmerror value
)
2023-07-24 11:18:25 +02:00
//goland:noinspection GoUnusedGlobalVariable
2023-02-15 16:04:19 +01:00
var AllCategories = [ ] ErrorCategory { CatWrap , CatSystem , CatUser , CatForeign }
type ErrorSeverity struct { Severity string }
var (
SevTrace = ErrorSeverity { "Trace" }
SevDebug = ErrorSeverity { "Debug" }
SevInfo = ErrorSeverity { "Info" }
SevWarn = ErrorSeverity { "Warn" }
SevErr = ErrorSeverity { "Err" }
SevFatal = ErrorSeverity { "Fatal" }
)
2023-07-24 11:18:25 +02:00
//goland:noinspection GoUnusedGlobalVariable
2023-02-15 16:04:19 +01:00
var AllSeverities = [ ] ErrorSeverity { SevTrace , SevDebug , SevInfo , SevWarn , SevErr , SevFatal }
2023-07-24 10:42:39 +02:00
type ErrorType struct {
Key string
DefaultStatusCode * int
}
2023-02-15 16:04:19 +01:00
2023-07-24 11:18:25 +02:00
//goland:noinspection GoUnusedGlobalVariable
2023-02-15 16:04:19 +01:00
var (
2023-07-24 11:11:15 +02:00
TypeInternal = ErrorType { "INTERNAL_ERROR" , langext . Ptr ( 500 ) }
TypePanic = ErrorType { "PANIC" , langext . Ptr ( 500 ) }
TypeNotImplemented = ErrorType { "NOT_IMPLEMENTED" , langext . Ptr ( 500 ) }
TypeWrap = ErrorType { "Wrap" , nil }
TypeBindFailURI = ErrorType { "BINDFAIL_URI" , langext . Ptr ( 400 ) }
TypeBindFailQuery = ErrorType { "BINDFAIL_QUERY" , langext . Ptr ( 400 ) }
TypeBindFailJSON = ErrorType { "BINDFAIL_JSON" , langext . Ptr ( 400 ) }
TypeBindFailFormData = ErrorType { "BINDFAIL_FORMDATA" , langext . Ptr ( 400 ) }
TypeUnauthorized = ErrorType { "UNAUTHORIZED" , langext . Ptr ( 401 ) }
TypeAuthFailed = ErrorType { "AUTH_FAILED" , langext . Ptr ( 401 ) }
2023-02-15 16:04:19 +01:00
// other values come from pkgconfig
)
2023-07-24 10:42:39 +02:00
2023-07-24 11:18:25 +02:00
func NewType ( key string , defStatusCode * int ) ErrorType {
2023-07-24 11:16:57 +02:00
return ErrorType { key , defStatusCode }
}
2023-07-24 10:42:39 +02:00
type LogPrintLevel string
const (
LogPrintFull LogPrintLevel = "Full"
LogPrintOverview LogPrintLevel = "Overview"
LogPrintShort LogPrintLevel = "Short"
)