1
0
mirror of https://git.sr.ht/~yotam/shavit synced 2024-11-29 20:18:00 +01:00
shavit/recover.go
2019-12-06 21:22:18 +02:00

21 lines
536 B
Go

package main
import (
gemini "git.sr.ht/~yotam/go-gemini"
)
// RecovererHandler wrap a Gemini handler and recover from panics
type RecovererHandler struct {
handler gemini.Handler
}
// Handle implement the gemini.Handler interface by recovering inner handler
func (h RecovererHandler) Handle(req gemini.Request) (res gemini.Response) {
defer func() {
if r := recover(); r != nil {
res = gemini.Response{Status: gemini.StatusTemporaryFailure, Meta: "Internal server error", Body: nil}
}
}()
return h.handler.Handle(req)
}