Documentation
¶
Overview ¶
apperror/apperror.go
Index ¶
- Constants
- func As(err error, target any) bool
- func HTTPMiddleware(next http.Handler) http.Handler
- func Is(err, target error) bool
- func OnError(hook func(*AppError))
- func Register(name string, e *AppError) error
- func Unregister(name string) error
- func Update(name string, e *AppError) error
- func WriteJSONError(w http.ResponseWriter, r *http.Request, err error)
- type AppError
- func Get(name string) (*AppError, bool)
- func GetByCode(code string) (*AppError, bool)
- func Instance(e *AppError) *AppError
- func List() []*AppError
- func New(httpCode, appCode, domainCode, errCode int, msg string) *AppError
- func Wrap(err error, httpCode, appCode, domainCode, errCode int, msg string) *AppError
- type ErrorRegistry
Constants ¶
View Source
const ( EnvDevelopment = "development" EnvStaging = "staging" EnvProduction = "production" )
APP_ENV values
Variables ¶
This section is empty.
Functions ¶
func HTTPMiddleware ¶
HTTPMiddleware catches panics and converts to JSON 500
func WriteJSONError ¶
func WriteJSONError(w http.ResponseWriter, r *http.Request, err error)
WriteJSONError writes an error as JSON, includes X-Request-ID, hides details in production
Types ¶
type AppError ¶
type AppError struct {
Code string `json:"code"` // 9-digit code: XXX|AA|DD|YY
Message string `json:"message"` // human-readable message
StatusCode int `json:"-"` // HTTP status, not serialized
Err error `json:"-"` // wrapped error, not serialized
Metadata map[string]any `json:"metadata,omitempty"` // optional extra info
StackTrace []string `json:"stackTrace,omitempty"`
}
AppError defines a structured application error
func (*AppError) GetStackTraceArray ¶
GetStackTraceArray returns the error stack trace as an array of strings
func (*AppError) GetStackTraceString ¶
GetStackTraceString returns the error stack trace as a single string
type ErrorRegistry ¶
type ErrorRegistry struct {
// contains filtered or unexported fields
}
func (*ErrorRegistry) Delete ¶
func (er *ErrorRegistry) Delete(name string)
func (*ErrorRegistry) List ¶
func (er *ErrorRegistry) List() []*AppError
func (*ErrorRegistry) Set ¶
func (er *ErrorRegistry) Set(name string, e *AppError)
Click to show internal directories.
Click to hide internal directories.