Errors
Zinc uses HTTPError for structured HTTP failures.
HTTPError
type HTTPError struct {
Code int
Message string
Cause error
Meta zinc.Map
Headers http.Header
}
Useful methods:
WithMessageWithCauseWithMetaWithHeader
Create errors
return zinc.NewError(zinc.StatusBadRequest).WithMessage("invalid payload")
Predefined errors
Zinc includes ready-made errors for common HTTP statuses, including:
ErrBadRequestErrUnauthorizedErrForbiddenErrNotFoundErrMethodNotAllowedErrTooManyRequestsErrInternalServerError
Error handling hook
Set Config.ErrorHandler to control how returned errors are rendered.
That is the right place to implement a project-wide JSON error envelope.