error

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func APIErrorHanderFunc(e error, c echo.Context) (bool, error)

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

func DefaultErrorHanderFunc(err error, c echo.Context) (bool, error)

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

func HTTPErrorHanderFunc(e error, c echo.Context) (bool, error)

func ValidationErrorHanderFunc

func ValidationErrorHanderFunc(e error, c echo.Context) (bool, error)

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

func NewAPIError(HTTPStatusCode int, globalErrCode ErrorCode, err error) *APIError

NewAPIError returns the proper error object from {{ .PkgPath }}. You must provide `error` interface as 3rd parameter.

func NewIgnorableAPIError added in v1.1.14

func NewIgnorableAPIError(HTTPStatusCode int, globalErrCode ErrorCode, err error) *APIError

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.

func (*APIError) Error

func (e *APIError) Error() string

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())

func (*APIError) String

func (e *APIError) String() string

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"
)

type ErrorHandlerFunc

type ErrorHandlerFunc func(err error, c echo.Context) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL