httperror: github.com/shurcooL/httperror Index | Files

package httperror

import "github.com/shurcooL/httperror"

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

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

Index

Package Files

doc.go error.go handle.go

func HandleBadRequest Uses

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 Uses

func HandleMethod(w http.ResponseWriter, err Method)

HandleMethod handles a method error.

type BadRequest Uses

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

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

func IsBadRequest Uses

func IsBadRequest(err error) (BadRequest, bool)

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

func (BadRequest) Error Uses

func (b BadRequest) Error() string

Error returns BadRequest.Err.Error().

type HTTP Uses

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 Uses

func IsHTTP(err error) (HTTP, bool)

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

func (HTTP) Error Uses

func (h HTTP) Error() string

Error returns HTTP.Err.Error().

type JSONResponse Uses

type JSONResponse struct {
    V interface{}
}

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

func IsJSONResponse Uses

func IsJSONResponse(err error) (JSONResponse, bool)

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

func (JSONResponse) Error Uses

func (JSONResponse) Error() string

type Method Uses

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

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

func IsMethod Uses

func IsMethod(err error) (Method, bool)

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

func (Method) Error Uses

func (m Method) Error() string

type Redirect Uses

type Redirect struct {
    URL string
}

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

func IsRedirect Uses

func IsRedirect(err error) (Redirect, bool)

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

func (Redirect) Error Uses

func (r Redirect) Error() string

Package httperror imports 3 packages (graph) and is imported by 15 packages. Updated 2017-09-13. Refresh now. Tools for package owners.