Recover panics in finishRequest, write correct API response

This commit is contained in:
Jordan Liggitt
2015-08-28 14:01:31 -04:00
parent cb2252b57f
commit b5e8f7aa41
4 changed files with 38 additions and 18 deletions

View File

@@ -44,7 +44,8 @@ var ReallyCrash bool
var PanicHandlers = []func(interface{}){logPanic}
// HandleCrash simply catches a crash and logs an error. Meant to be called via defer.
func HandleCrash() {
// Additional context-specific handlers can be provided, and will be called in case of panic
func HandleCrash(additionalHandlers ...func(interface{})) {
if ReallyCrash {
return
}
@@ -52,6 +53,9 @@ func HandleCrash() {
for _, fn := range PanicHandlers {
fn(r)
}
for _, fn := range additionalHandlers {
fn(r)
}
}
}