panic if err is nil on c.Error

A panic here provides a more informative stack trace than the panic which would otherwise occur while errors are being collected.
This commit is contained in:
Ammar Bandukwala
2017-05-08 19:04:22 -05:00
parent d4a53101c3
commit 781cbd19f0
2 changed files with 11 additions and 0 deletions

View File

@ -144,7 +144,11 @@ func (c *Context) AbortWithError(code int, err error) *Error {
// It's a good idea to call Error for each error that occurred during the resolution of a request.
// A middleware can be used to collect all the errors
// and push them to a database together, print a log, or append it in the HTTP response.
// Error will panic if err is nil.
func (c *Context) Error(err error) *Error {
if err == nil {
panic("err is nil")
}
var parsedError *Error
switch err.(type) {
case *Error: