Recover panics in finishRequest, write correct API response
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user