1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 05:25:58 +00:00

new app.MiddlewareExists method

This commit is contained in:
Gerasimos (Makis) Maropoulos
2024-01-21 17:16:59 +02:00
parent 4eb7705fae
commit 66e3c26efe
8 changed files with 125 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
"github.com/kataras/iris/v12/context"
@@ -20,6 +21,11 @@ type LogErrorFunc = func(ctx *context.Context, err error)
// LogError can be modified to customize the way an error is logged to the server (most common: internal server errors, database errors et.c.).
// Can be used to customize the error logging, e.g. using Sentry (cloud-based error console).
var LogError LogErrorFunc = func(ctx *context.Context, err error) {
if ctx == nil {
slog.Error(err.Error())
return
}
ctx.Application().Logger().Error(err)
}

View File

@@ -13,6 +13,10 @@ import (
"golang.org/x/exp/constraints"
)
func init() {
context.SetHandlerName("iris/x/errors.RecoveryHandler.*", "iris.errors.recover")
}
// RecoveryHandler is a middleware which recovers from panics and sends an appropriate error response
// to the logger and the client.
func RecoveryHandler(ctx *context.Context) {