mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 17:56:20 +03:00
panics get logged at error level, now include stacktrace
Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
3fb5890f3a
commit
ddf4fb9efa
1 changed files with 9 additions and 1 deletions
|
@ -22,6 +22,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"codeberg.org/gruf/go-errors/v2"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||||
|
@ -107,7 +108,14 @@ func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet fun
|
||||||
// we should still try to return a basic code
|
// we should still try to return a basic code
|
||||||
defer func() {
|
defer func() {
|
||||||
if p := recover(); p != nil {
|
if p := recover(); p != nil {
|
||||||
l.Warnf("recovered from panic: %s", p)
|
// Fetch stacktrace up to this point
|
||||||
|
callers := errors.GetCallers(3, 10)
|
||||||
|
|
||||||
|
// Log this panic to the standard log
|
||||||
|
l = l.WithField("stacktrace", callers)
|
||||||
|
l.Errorf("recovered from panic: %v", p)
|
||||||
|
|
||||||
|
// Respond with determined error code
|
||||||
c.JSON(statusCode, gin.H{"error": errWithCode.Safe()})
|
c.JSON(statusCode, gin.H{"error": errWithCode.Safe()})
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue