MCPcopy
hub / github.com/pocketbase/pocketbase / panicRecover

Function panicRecover

apis/middlewares.go:253–283  ·  view source on GitHub ↗

panicRecover returns a default panic-recover handler.

()

Source from the content-addressed store, hash-verified

251
252// panicRecover returns a default panic-recover handler.
253func panicRecover() *hook.Handler[*core.RequestEvent] {
254 return &hook.Handler[*core.RequestEvent]{
255 Id: DefaultPanicRecoverMiddlewareId,
256 Priority: DefaultPanicRecoverMiddlewarePriority,
257 Func: func(e *core.RequestEvent) (err error) {
258 // panic-recover
259 defer func() {
260 recoverResult := recover()
261 if recoverResult == nil {
262 return
263 }
264
265 recoverErr, ok := recoverResult.(error)
266 if !ok {
267 recoverErr = fmt.Errorf("%v", recoverResult)
268 } else if errors.Is(recoverErr, http.ErrAbortHandler) {
269 // don't recover ErrAbortHandler so the response to the client can be aborted
270 panic(recoverResult)
271 }
272
273 stack := make([]byte, 2<<10) // 2 KB
274 length := runtime.Stack(stack, true)
275 err = e.InternalServerError("", fmt.Errorf("[PANIC RECOVER] %w %s", recoverErr, stack[:length]))
276 }()
277
278 err = e.Next()
279
280 return err
281 },
282 }
283}
284
285// securityHeaders middleware adds common security headers to the response.
286//

Callers 1

NewRouterFunction · 0.85

Calls 3

IsMethod · 0.80
InternalServerErrorMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…