gofiber / jwt

⚠️ Deprecated repository, available within Fiber Contrib.
https://github.com/gofiber/contrib/tree/main/jwt
MIT License
393 stars 31 forks source link

Jwt middleware not using fiber ErrorHandler #40

Open Andrflor opened 3 years ago

Andrflor commented 3 years ago

Hello, I was wondering if it's and intended behavior... (Code may be better to explain)

The default error handler is written

    if cfg.ErrorHandler == nil {
        cfg.ErrorHandler = func(c *fiber.Ctx, err error) error {
            if err.Error() == "Missing or malformed JWT" {
                return c.Status(fiber.StatusBadRequest).SendString("Missing or malformed JWT")
            } else {
                return c.Status(fiber.StatusUnauthorized).SendString("Invalid or expired JWT")
            }
        }
    }

This way the error is not processed trough the app error handler Should it not be that way to be processed by any application level error handler by default?

    if cfg.ErrorHandler == nil {
        cfg.ErrorHandler = func(c *fiber.Ctx, err error) error {
            if err.Error() == "Missing or malformed JWT" {
                return fiber.NewError(fiber.StatusBadRequest, "Missing or malformed JWT")
            } else {
                return fiber.NewError(fiber.StatusUnauthorized, "Invalid or expired JWT")
            }
        }
    }

Not sure if i am clear enough 😅

shytikov commented 3 years ago

Just to add some information – BasicAuth middleware not using that approach: https://github.com/gofiber/fiber/blob/9dd39c0e55376b68b368a82f181446da8d96962f/middleware/basicauth/config.go#L94

But for me it makes sense... Will continue digging...