errorhandler

package
v0.0.0-...-3a75ae7 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrorHandler = ErrorHandlerFunc(func(w http.ResponseWriter, r *http.Request, err error) {
	if err, ok := err.(httperror.HttpError); ok {
		http.Error(w, err.Error(), err.StatusCode())
		return
	}

	http.Error(w, err.Error(), http.StatusInternalServerError)
})

DefaultErrorHandler is the default error handler.

Functions

func WithErrorHandler

func WithErrorHandler(errorHandler ErrorHandler) func(HandlerFunc) http.HandlerFunc

WithErrorHandler returns an http.Handler that handles errors by errorHandler.

Types

type ErrorHandler

type ErrorHandler interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request, err error)
}

ErrorHandler is an interface that can handle errors returned by an Handler.

type ErrorHandlerFunc

type ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)

ErrorHandlerFunc is an adapter to handle errors returned by an Handler.

func (ErrorHandlerFunc) ServeHTTP

func (f ErrorHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err error)

type Handler

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

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

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request) error

HandlerFunc is an adapter to allow the use of ordinary functions as HTTP handlers.

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error

Jump to

Keyboard shortcuts

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