Documentation ¶
Index ¶
- Variables
- func ErrBadRequest(err error) render.Renderer
- func ErrInternalError(err error) render.Renderer
- func ErrInvalidRequest(err error) render.Renderer
- func ErrNotFound(err error) render.Renderer
- func ErrUnauthorized(err error) render.Renderer
- func ErrValidation(err error, valErr validation.Errors) render.Renderer
- type ErrResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // BadRequest return status 400 Bad Request for malformed request body. BadRequest = &ErrResponse{HTTPStatusCode: http.StatusBadRequest, StatusText: http.StatusText(http.StatusBadRequest)} // NotFound returns status 404 Not Found for invalid resource request. NotFound = &ErrResponse{HTTPStatusCode: http.StatusNotFound, StatusText: http.StatusText(http.StatusNotFound)} Unauthorized = &ErrResponse{HTTPStatusCode: http.StatusUnauthorized, StatusText: http.StatusText(http.StatusUnauthorized)} // Forbidden returns status 403 Forbidden for unauthorized request. Forbidden = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden)} // InternalServerError returns status 500 Internal Server Error. InternalServerError = &ErrResponse{HTTPStatusCode: http.StatusInternalServerError, StatusText: http.StatusText(http.StatusInternalServerError)} )
Functions ¶
func ErrBadRequest ¶
ErrBadRequest returns status 400 bad request including errors message.
func ErrInternalError ¶
ErrInternalError renders status 500 Internal server error with custom errors message.
func ErrInvalidRequest ¶
ErrInvalidRequest returns status 422 Unprocessable Entity including errors message.
func ErrNotFound ¶
ErrNotFound renders status 404 NotFound with custom errors message.
func ErrUnauthorized ¶
ErrUnauthorized renders status 401 Unauthorized with custom errors message.
func ErrValidation ¶
func ErrValidation(err error, valErr validation.Errors) render.Renderer
ErrValidation returns status 422 Unprocessable Entity stating validation errors.
Types ¶
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime errors HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message AppCode string `json:"code,omitempty"` // application-specific errors code ErrorText string `json:"errors,omitempty"` // application-level errors message, for debugging ValidationErrors validation.Errors `json:"validation_errors,omitempty"` // user level model validation errors }
ErrResponse renderer type for handling all sorts of errors.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
Render sets the application-specific errors code in AppCode.
Click to show internal directories.
Click to hide internal directories.