goext/exerr/data.go

96 lines
3.3 KiB
Go
Raw Normal View History

package exerr
2023-07-24 10:42:39 +02:00
import (
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
2023-07-24 10:42:39 +02:00
"gogs.mikescher.com/BlackForestBytes/goext/langext"
)
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
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
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-07-24 11:18:25 +02:00
//goland:noinspection GoUnusedGlobalVariable
var (
TypeInternal = NewType("INTERNAL_ERROR", langext.Ptr(500))
TypePanic = NewType("PANIC", langext.Ptr(500))
TypeNotImplemented = NewType("NOT_IMPLEMENTED", langext.Ptr(500))
2023-07-24 11:11:15 +02:00
2023-08-21 15:08:35 +02:00
TypeMongoQuery = NewType("MONGO_QUERY", langext.Ptr(500))
TypeCursorTokenDecode = NewType("CURSOR_TOKEN_DECODE", langext.Ptr(500))
TypeMongoFilter = NewType("MONGO_FILTER", langext.Ptr(500))
TypeMongoReflection = NewType("MONGO_REFLECTION", langext.Ptr(500))
2023-11-09 10:17:29 +01:00
TypeMongoInvalidOpt = NewType("MONGO_INVALIDOPT", langext.Ptr(500))
2023-08-21 15:08:35 +02:00
2024-01-14 00:07:01 +01:00
TypeSQLQuery = NewType("SQL_QUERY", langext.Ptr(500))
TypeSQLBuild = NewType("SQL_BUILD", langext.Ptr(500))
TypeSQLDecode = NewType("SQL_DECODE", langext.Ptr(500))
2024-01-05 16:53:14 +01:00
TypeWrap = NewType("Wrap", nil)
2023-07-24 11:11:15 +02:00
TypeBindFailURI = NewType("BINDFAIL_URI", langext.Ptr(400))
TypeBindFailQuery = NewType("BINDFAIL_QUERY", langext.Ptr(400))
TypeBindFailJSON = NewType("BINDFAIL_JSON", langext.Ptr(400))
TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", langext.Ptr(400))
TypeBindFailHeader = NewType("BINDFAIL_HEADER", langext.Ptr(400))
2023-07-24 11:11:15 +02:00
2023-09-18 10:38:25 +02:00
TypeMarshalEntityID = NewType("MARSHAL_ENTITY_ID", langext.Ptr(400))
2023-10-26 13:01:58 +02:00
TypeInvalidCSID = NewType("INVALID_CSID", langext.Ptr(400))
2023-09-18 10:38:25 +02:00
2023-12-04 13:48:11 +01:00
TypeGoogleStatuscode = NewType("GOOGLE_STATUSCODE", langext.Ptr(400))
TypeGoogleResponse = NewType("GOOGLE_RESPONSE", langext.Ptr(400))
TypeUnauthorized = NewType("UNAUTHORIZED", langext.Ptr(401))
TypeAuthFailed = NewType("AUTH_FAILED", langext.Ptr(401))
2023-07-24 11:11:15 +02:00
2024-01-04 12:38:03 +01:00
// other values come from the downstream application that uses goext
)
2023-07-24 10:42:39 +02:00
2024-01-07 04:18:03 +01:00
var registeredTypes = dataext.SyncMap[string, ErrorType]{}
2023-07-24 11:18:25 +02:00
func NewType(key string, defStatusCode *int) ErrorType {
2024-01-07 04:18:03 +01:00
et := ErrorType{key, defStatusCode}
2024-01-07 04:18:03 +01:00
registeredTypes.Set(key, et)
return et
}
func ListRegisteredTypes() []ErrorType {
return registeredTypes.GetAllValues()
2023-07-24 11:16:57 +02:00
}
2023-07-24 10:42:39 +02:00
type LogPrintLevel string
const (
LogPrintFull LogPrintLevel = "Full"
LogPrintOverview LogPrintLevel = "Overview"
LogPrintShort LogPrintLevel = "Short"
)