errors

package
v1.109.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleHTTPPanic

func HandleHTTPPanic(rw http.ResponseWriter, rq *http.Request)

HandleHTTPPanic should be executed in a deferred method (or deferred directly) in http middleware. It will capture any panics that occur in the goroutine it exists, and report to the registered global panic handler. HTTP handler panics will have the errors.PanicTypeHTTP Type.

func HandlePanic

func HandlePanic()

HandlePanic should be executed in a deferred method (or deferred directly). It will capture any panics that occur in the goroutine it exists, and report to the registered global panic handler.

func PanicHandlerMiddleware

func PanicHandlerMiddleware(handler http.Handler) http.Handler

PanicHandlerMiddleware should wrap any of the http handlers to capture panics.

func SetPanicHandler

func SetPanicHandler(handler PanicHandler) error

SetPanicHandler sets the handler that is executed when any panic is captured by HandlePanic(). Without setting a handler, the panic reporting is disabled.

Types

type Panic

type Panic struct {
	Error interface{}
	Stack string
	Type  PanicType
}

Panic represents a panic that occurred, captured by a recovery.

type PanicHandler

type PanicHandler = func(p Panic) bool

PanicHandler is a func that receives a Panic and returns a bool representing whether or not the panic should recover or not.

type PanicType

type PanicType int

PanicType defines the context in which the panic occurred

const (
	PanicTypeDefault PanicType = iota
	PanicTypeHTTP
)

func (PanicType) String

func (pt PanicType) String() string

The string representation of PanicContext

Jump to

Keyboard shortcuts

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