Documentation
¶
Index ¶
- Variables
- func APIErrorHanderFunc(e error, c echo.Context) (bool, error)
- func DefaultErrorHanderFunc(err error, c echo.Context) (bool, error)
- func HTTPErrorHanderFunc(e error, c echo.Context) (bool, error)
- func ValidationErrorHanderFunc(e error, c echo.Context) (bool, error)
- type APIError
- type ErrorCode
- type ErrorHandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrInternalServer = errors.New("internal server error") ErrInvalidJsonResponse = errors.New("invalid JSON response") ErrContextExtraction = errors.New("some data is missing in the context") ErrParamMissing = errors.New("parameters are missing") ErrUpstreamTimeout = errors.New("timeout from upstream server") ErrTimeout = errors.New("timeout") )
Functions ¶
func APIErrorHanderFunc ¶
Default JSON API error handler. The response pattern is like below: `{"errorCode": "1000001", "errorMsg": "some message"}`. You can override this error handler from `start.go`
func DefaultErrorHanderFunc ¶
If any other error handler doesn't catch the error then finally `DefaultErrorHanderFunc` will cactch the error and treat all those errors as `http.StatusInternalServerError`.
func HTTPErrorHanderFunc ¶ added in v1.2.0
Types ¶
type APIError ¶
type APIError struct { HTTPStatusCode int GlobalErrCode ErrorCode Err error Ignorable bool // An extra option to control the behaviour. (example: push to some error tracker or not) *stacktrace.Stack }
APIError represents the error object of {{ .PkgPath }} API error.
func NewAPIError ¶
NewAPIError returns the proper error object from {{ .PkgPath }}. You must provide `error` interface as 3rd parameter.
func NewIgnorableAPIError ¶ added in v1.1.14
NewIgnorableAPIError returns the proper error object from {{ .PkgPath }}, the error tracker like sentry will not push this type of error online. You must provide `error` interface as 3rd parameter.
type ErrorCode ¶
type ErrorCode string
const ( API_SUCCESS ErrorCode = "000000" // API general error code PROBLEM_PARSING_JSON ErrorCode = "100001" UNAUTHORIZED_ACCESS ErrorCode = "100002" RESOURCE_NOT_FOUND ErrorCode = "100003" INTERNAL_SERVER_ERROR ErrorCode = "100004" REQUEST_ENTITY_TOO_LARGE ErrorCode = "100005" METHOD_NOT_ALLOWED ErrorCode = "100006" SERVICE_DOWN_FOR_MAINTENANCE ErrorCode = "100009" TOO_MANY_REQUESTS ErrorCode = "100010" UNKNOWN_ERROR_CODE ErrorCode = "100098" TIMEOUT ErrorCode = "100099" // API parameter error code API_DATA_VALIDATION_FAILED ErrorCode = "200001" )