Skip to content

✨ v3 (feature): use any as default Message type of Error struct #1925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 12, 2022

Conversation

efectn
Copy link
Member

@efectn efectn commented May 31, 2022

closes #1825

@efectn efectn linked an issue May 31, 2022 that may be closed by this pull request
@efectn efectn added the v3 label May 31, 2022
@efectn efectn added this to the v3 milestone Jun 4, 2022
@harryrford
Copy link

harryrford commented Jun 8, 2022

On a side note for the v3 fiber Error type shouldn't we include a method added to the Ctx such as ctx.SendError(err Error) to encourage usage of the type (as an exported package defined variable) and avoid writing helpers such as:

func SendError(c *fiber.Ctx, code int, message string) error {
	c.Status(code)
	return c.JSON(fiber.NewError(code, message))
}

Instead a method could simply be defined as:

func (c *Ctx) SendError(err Error) error {
	c.Status(err.Code)
	return c.JSON(err)
}

@efectn
Copy link
Member Author

efectn commented Jun 8, 2022

On a side note for the v3 fiber Error type shouldn't we include a method added to the Ctx such as ctx.SendError(err Error) to encourage usage of the type (as an exported package defined variable) and avoid writing helpers such as:

func SendError(c *fiber.Ctx, code int, message string) error {
	c.Status(code)
	return c.JSON(fiber.NewError(code, message))
}

Instead a method could simply be defined as:

func (c *Ctx) SendError(err Error) error {
	c.Status(err.Code)
	return c.JSON(err)
}

I don't think it's good idea to add SendError method into the context. Because some people may want to just send error message instead of Error struct. It's very specific. Probably this PR will be helpful for your use case: #1928

@ReneWerner87 ReneWerner87 merged commit e35a594 into v3-beta Jun 12, 2022
@efectn efectn deleted the v3-errors branch June 14, 2022 11:21
efectn added a commit that referenced this pull request Aug 7, 2022
ReneWerner87 pushed a commit that referenced this pull request Aug 8, 2022
…of Error struct (#1925)" (#2000)

Revert ":sparkles: v3 (feature): use any as default Message type of Error struct (#1925)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

🚀 v3 Request: fiber.Error's message type of interface{}
3 participants