httperr

package
v0.0.0-...-2597ab7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package httperr adds idiomatic error handling to net/http and httprouter Handle(r)s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Formatf

func Formatf(code int, format string, a ...interface{}) error

Formatf returns an error that induces this package's Handle(r)s to send the specified HTTP code. If the code is 200, the returned error is nil. Only 400-level codes have their messages propagated. All other codes result in the error message being hashed and logged, with only a portion of the hash returned to the end user for reporting.

func HandlerFunc

func HandlerFunc(fn func(http.ResponseWriter, *http.Request) error) http.HandlerFunc

HandlerFunc allows http.HandlerFunc-like functions to return errors. If the returned error is one returned by Formatf(), it is treated as described in that function's documentation. All other errors are treated as 500.

func RouterHandle

RouterHandle is equivalent to HandlerFunc, but also supports propagation of httprouter.Params.

func WithStatus

func WithStatus(code int, err error) error

WithStatus converts err into an error with the same behaviour as those returned by Formatf().

Types

This section is empty.

Jump to

Keyboard shortcuts

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