package apperror import "fmt" // AppError should be created by the inner packages. // Later, the handler layer can wrap them into errors like StatusError, AbortError, JSONError, RedirectError. type AppError struct { code string message string err error } // New creates an AppError func New(err error, code string, msg string) *AppError { return &AppError{ code: code, message: msg, err: err, } } func (e AppError) Error() string { return fmt.Sprintf("%s <%s>. %v", e.message, e.code, e.err.Error()) } func (e AppError) Unwrap() error { return e.err } func (e AppError) ErrorCode() string { return e.code }