Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Unable to parse JSON Decoder Error #1751

Closed
kivox opened this issue Feb 4, 2022 · 2 comments
Closed

馃悰 Unable to parse JSON Decoder Error #1751

kivox opened this issue Feb 4, 2022 · 2 comments

Comments

@kivox
Copy link

kivox commented Feb 4, 2022

Fiber version
Fiber v2.25.0

Issue description
Usually, you can unmarshal the error returned by a function into the struct it was declared as. Now the issue here is this struct is set as an internal property of the Fiber library, therefore, making it inaccessible to the project where Fiber is used in.

Location of the decoder's Error struct: github.com/gofiber/fiber/v2/internal/go-json/errors

Code snippet

func ParseBody(ctx *fiber.Ctx, body interface{}) *fiber.Error {
	// parse request to struct
	if err := ctx.BodyParser(body); err != nil {
		// This should parse the error's string into a struct of the error
		if jsonErr, ok := err.(*errors.UnmarshalTypeError); ok {
			// use jsonErr to get values from error
		} else {
			// The error is not an UnmarshalTypeError
			return fiber.ErrBadRequest
		}
	}

	return nil
}
@welcome
Copy link

welcome bot commented Feb 4, 2022

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

@ReneWerner87
Copy link
Member

Should be fixed by #1755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants