summaryrefslogtreecommitdiff
path: root/recover.go
blob: 7be6fc63b904e9dac57bab9ab3ad6ef8597010c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import (
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
	"net/http"
)

func recovery() gin.HandlerFunc {
	return func(context *gin.Context) {
		defer func() {
			p := recover()
			if p != nil {
				log.Errorf("Panic occurred in web server, %s", p)
				context.JSON(http.StatusInternalServerError, gin.H{
					"error": p,
				})
			}
		}()
		context.Next()
	}
}