Documentation
¶
Index ¶
- Variables
- func APIErrorHandlerFunc(e error, c echo.Context) (bool, error)
- func DefaultErrorHandlerFunc(err error, c echo.Context) (bool, error)
- func HTTPErrorHandlerFunc(e error, c echo.Context) (bool, error)
- func NewAPIError(HTTPStatusCode int, globalErrCode ErrorCode, err error) error
- func NewIgnorableAPIError(HTTPStatusCode int, globalErrCode ErrorCode, err error) error
- func ValidationErrorHandlerFunc(e error, c echo.Context) (bool, error)
- type APIError
- type ErrorCode
- type ErrorHandlerFunc
- type ErrorResp
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 APIErrorHandlerFunc ¶
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 DefaultErrorHandlerFunc ¶
If any other error handler doesn't catch the error then finally `DefaultErrorHandlerFunc` will cactch the error and treat all those errors as `http.StatusInternalServerError`.
func NewAPIError ¶
NewAPIError returns the proper error object from {{ .PkgPath }}. You must provide `error` interface as 3rd parameter.
func NewIgnorableAPIError ¶
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.
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 (*APIError) Error ¶
This function need to be call explicitly because the APIError embedded the *stacktrace.Stack which already implemented the Format() function and treat it as a formatter. Example: fmt.Println(e.String())
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" )