Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultFormatter = func(errMsg string, stack []byte, file string, line int, fullMessages bool) interface{} {
return newJSONPanicError(errMsg, fullMessages, file, line)
}
DefaultFormatter returns a jsonPanicError constructed from the parameters. jsonPanicError contains 4 fields: - Code: the http status code (always 500) - Short: a short message specifying what error occured (always "internalError") - Errors: an array of error messages - From: the file and line number where the error originated
var Formatter func(errMsg string, stack []byte, file string, line int, fullMessages bool) interface{} = DefaultFormatter
Formatter lets you specify any arbitrary interface based on the function parameters which will be converted to JSON and written to the response.
var IndentJSON = false
IndentJSON specifies whether or not to indent (or pretty print) the json returned when there is a panic. The default is false.
var StackDepth = 2
StackDepth lets you specify how many stack frames to skip before reaching the file and line number you care about. You probably want to set this so that recovery skips frames in the stack until it reaches the line where panic was called. This can depend on how you included the middleware and recovered from panics. The default is 2
Functions ¶
func JSONRecovery ¶
func JSONRecovery(fullMessages bool) negroni.HandlerFunc
JSONRecovery returns a middleware function which catches any panics and wraps them up into a JSON response. Set fullMessages to true if you would like to show full error messages with line numbers and false if you would like to protect this information. Typically, in development mode you would set fullMessages to true, but in production you would set it to false.
Types ¶
type JSONPanicError ¶
type JSONPanicError struct { Code int `json:"code,omitempty"` // the http response code Short string `json:"short,omitempty"` // a short explanation of the response (usually one or two words). for internal use only Errors []interface{} `json:"errors,omitempty"` // any errors that may have occured with the request and should be displayed to the user From string `json:"from,omitempty"` // the file and line number from which the error originated }
func (JSONPanicError) Error ¶
func (je JSONPanicError) Error() string