gohttperror

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Error rendering Documentation Go Report Card Coverage Status CircleCI Maintainability

From go-chi examples

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{
	HTTPStatusCode: http.StatusNotFound,
	StatusText:     "Resource not found",
}

ErrNotFound is the wrapped error for not found resources

View Source
var ErrNotImplemented = &ErrResponse{
	HTTPStatusCode: http.StatusNotImplemented,
	StatusText:     "Method not implemented",
}

ErrNotImplemented is the wrapped error for not implemented methods

Functions

This section is empty.

Types

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	ErrorText  string `json:"error,omitempty"` // application-level error
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func ErrBadRequest

func ErrBadRequest(err error) *ErrResponse

ErrBadRequest when supplied data is not correct

func ErrForbidden

func ErrForbidden(err error) *ErrResponse

ErrForbidden when there is a server side issue

func ErrInternal

func ErrInternal(err error) *ErrResponse

ErrInternal when there is a server side issue

func ErrUnauthorized

func ErrUnauthorized(err error) *ErrResponse

ErrUnauthorized when there is a server side issue

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render rendering the error

Jump to

Keyboard shortcuts

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