handler

package
v0.0.0-...-bb1c6aa Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodNotAllowed = &ErrorResponse{
		StatusCode: http.StatusMethodNotAllowed,
		StatusText: "Method not allowed.",
		Message:    "Method not allowed. Check the documentation for the correct endpoints.",
	}
	ErrUnauthorized = &ErrorResponse{
		StatusCode: http.StatusUnauthorized,
		StatusText: "Unauthorized.",
		Message:    "You're not authorized. Please check your credentials and try again.",
	}
	ErrNotFound = &ErrorResponse{
		StatusCode: http.StatusNotFound,
		StatusText: "Resource not found.",
		Message:    "Resource not found. Check the given identifier and try again.",
	}
	ErrBadRequest = &ErrorResponse{
		StatusCode: http.StatusBadRequest,
		Message:    "Bad request. Check the data sent in the request an try again.",
	}
)

Functions

func AddCustomErrorHandlerfunc

func AddCustomErrorHandlerfunc(writer http.ResponseWriter, request *http.Request, value interface{})

func NewHandler

func NewHandler() http.Handler

func UnauthorizedHandler

func UnauthorizedHandler(writer http.ResponseWriter)

Types

type ErrorResponse

type ErrorResponse struct {
	Err        error  `json:"-"`
	StatusCode int    `json:"-"`
	StatusText string `json:"-"`
	Message    string `json:"message"`
}

func ErrorRenderer

func ErrorRenderer(err error) *ErrorResponse

func ServerErrorRenderer

func ServerErrorRenderer(err error) *ErrorResponse

func (*ErrorResponse) Render

func (errorResponse *ErrorResponse) Render(writer http.ResponseWriter, request *http.Request) error

Jump to

Keyboard shortcuts

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