PanicHandler catches panics to make sure that we recover from panics during GraphQL request execution and return an appropriate error. If PanicHandler recovers from a panic, it logs a stack trace, creates an error and applies fn to the error.
(fn func(error), query string)
| 18 | // If PanicHandler recovers from a panic, it logs a stack trace, creates an error |
| 19 | // and applies fn to the error. |
| 20 | func PanicHandler(fn func(error), query string) { |
| 21 | if err := recover(); err != nil { |
| 22 | // Log the panic along with query which caused it. |
| 23 | glog.Errorf("panic: %s.\n query: %s\n trace: %s", err, query, string(debug.Stack())) |
| 24 | |
| 25 | fn(errors.Errorf("Internal Server Error - a panic was trapped. " + |
| 26 | "This indicates a bug in the GraphQL server. A stack trace was logged. " + |
| 27 | "Please let us know by filing an issue with the stack trace.")) |
| 28 | } |
| 29 | } |
no test coverage detected