aboutsummaryrefslogtreecommitdiff
path: root/recover.go
blob: b4a82e78c1e1a721784e7183020c3d4512168f82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)
}