diff options
Diffstat (limited to 'internal/api/errorhandling.go')
-rw-r--r-- | internal/api/errorhandling.go | 37 |
1 files changed, 1 insertions, 36 deletions
diff --git a/internal/api/errorhandling.go b/internal/api/errorhandling.go index 834f49ee8..32699fe36 100644 --- a/internal/api/errorhandling.go +++ b/internal/api/errorhandling.go @@ -22,7 +22,6 @@ import ( "context" "net/http" - "codeberg.org/gruf/go-errors/v2" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" @@ -86,47 +85,13 @@ func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context, d // if something goes wrong during the function, it will recover and just try to serve // an appropriate application/json content-type error. func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode)) { - path := c.Request.URL.Path - if raw := c.Request.URL.RawQuery; raw != "" { - path = path + "?" + raw - } - - l := logrus.WithFields(logrus.Fields{ - "path": path, - "error": errWithCode.Error(), - }) - - statusCode := errWithCode.Code() - - if statusCode == http.StatusInternalServerError { - l.Error("Internal Server Error") - } else { - l.Debug("handling error") - } - - // if we panic for any reason during error handling, - // we should still try to return a basic code - defer func() { - if p := recover(); p != nil { - // 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()}) - } - }() - // discover if we're allowed to serve a nice html error page, // or if we should just use a json. Normally we would want to // check for a returned error, but if an error occurs here we // can just fall back to default behavior (serve json error). accept, _ := NegotiateAccept(c, HTMLOrJSONAcceptHeaders...) - if statusCode == http.StatusNotFound { + if errWithCode.Code() == http.StatusNotFound { // use our special not found handler with useful status text NotFoundHandler(c, instanceGet, accept) } else { |