Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Jwt middleware not using fiber ErrorHandler #40

Open
Andrflor opened this issue May 15, 2021 · 1 comment
Open

Jwt middleware not using fiber ErrorHandler #40

Andrflor opened this issue May 15, 2021 · 1 comment
Labels
🤔 Question Further information is requested

Comments

@Andrflor
Copy link

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 😅

@ReneWerner87 ReneWerner87 added the 🤔 Question Further information is requested label May 25, 2021
@shytikov
Copy link
Contributor

shytikov commented Sep 6, 2021

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants