fiber icon indicating copy to clipboard operation
fiber copied to clipboard

📝 [Proposal]: Upgrade fiber.NewError() for error handle

Open pwtitle opened this issue 1 year ago • 2 comments

Feature Proposal Description

i want use Custom ErrorHandler to handle my error, but now fiber.NewError() has missed my message params

for example i want use fiber.NewError like this:

return fiber.NewError(45001, "my error message", 401)

on fiber.NewError() will missed my params : 401

image

can you change the Error and NewError() like this:

image

i will handle the error in my Custom ErrorHandler:

image

Alignment with Express API

nothing

HTTP RFC Standards Compliance

nothing

API Stability

nothing

Feature Examples

nothing

Checklist:

  • [X] I agree to follow Fiber's Code of Conduct.
  • [X] I have searched for existing issues that describe my proposal before opening this one.
  • [X] I understand that a proposal that does not meet these guidelines may be closed without explanation.

pwtitle avatar Jun 24 '24 12:06 pwtitle

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

welcome[bot] avatar Jun 24 '24 12:06 welcome[bot]

@pwtitle hi, i think you have a very specific problem that does not match the requirements of other consumers

the fiber.Error struct is public and you can fill it without the NewError method

ReneWerner87 avatar Jun 24 '24 13:06 ReneWerner87

I'm not sure if this should be considered at all. this is fixable by creating a custom error implementing the error interface and returning it at every error occurrence if I'm not mistaken. The error handler doesn't exactly needs it to be a fiber.Error struct, it only needs the error to be compliant with the error interface.

I could be wrong about this, but from what I've gathered reading the ErrorHandler config parameters, this is what I could understand.

luk3skyw4lker avatar Jul 10 '24 15:07 luk3skyw4lker

right, so I think this requirement is too specific for a special case and can already be handled well with custom errors

ReneWerner87 avatar Jul 10 '24 16:07 ReneWerner87