httperror

package module
v0.0.0-...-9bb3cab Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 4 Imported by: 23

README

httperror

Go Reference Build Status

Package httperror provides common basic building blocks for custom HTTP frameworks.

The API of this package is not stable at this time.

Installation

go get github.com/shurcooL/httperror

License

Documentation

Overview

Package httperror provides common basic building blocks for custom HTTP frameworks.

The API of this package is not stable at this time.

Index

Constants

This section is empty.

Variables

View Source
var NotHandle = errors.New("httperror: maybe HTTP handler chose to not handle request")

NotHandle is returned by a maybe HTTP handler to report that it explicitly chose to not handle the given HTTP request.

Functions

func HandleBadRequest

func HandleBadRequest(w http.ResponseWriter, err BadRequest)

HandleBadRequest handles a bad request error. The contents of err.Err are displayed to user, so you shouldn't include any sensitive information there, only information about the bad request.

func HandleMethod

func HandleMethod(w http.ResponseWriter, err Method)

HandleMethod handles a method error.

Types

type BadRequest

type BadRequest struct {
	Err error // Not nil.
}

BadRequest is an error type used for representing a bad request error.

func IsBadRequest

func IsBadRequest(err error) (BadRequest, bool)

IsBadRequest reports if err is considered a bad request error, returning it if so.

func (BadRequest) Error

func (b BadRequest) Error() string

Error returns BadRequest.Err.Error().

type HTTP

type HTTP struct {
	Code int
	Err  error // Not nil.
}

HTTP is an error type used for representing a non-nil error with a status code.

func IsHTTP

func IsHTTP(err error) (HTTP, bool)

IsHTTP reports if err is considered an HTTP error, returning it if so.

func (HTTP) Error

func (h HTTP) Error() string

Error returns HTTP.Err.Error().

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request) error
}

Handler is like http.Handler, but with an error return value.

If ServeHTTP returns a non-nil error value, the caller is expected to handle it in some way, taking into account whether the ResponseWriter was already written to.

type JSONResponse

type JSONResponse struct {
	V interface{}
}

JSONResponse is an error type used for representing a JSON response.

func IsJSONResponse

func IsJSONResponse(err error) (JSONResponse, bool)

IsJSONResponse reports if err is considered a JSON response, returning it if so.

func (JSONResponse) Error

func (JSONResponse) Error() string

type Method

type Method struct {
	Allowed []string // Allowed methods.
}

Method is an error type used for methods that aren't allowed.

func IsMethod

func IsMethod(err error) (Method, bool)

IsMethod reports if err is considered a method error, returning it if so.

func (Method) Error

func (m Method) Error() string

type Redirect

type Redirect struct {
	URL string
}

Redirect is an error type used for representing a simple HTTP redirection.

func IsRedirect

func IsRedirect(err error) (Redirect, bool)

IsRedirect reports if err is considered a redirect, returning it if so.

func (Redirect) Error

func (r Redirect) Error() string

Jump to

Keyboard shortcuts

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