Error

This contains the error information that thrown by a panic or passed via the Next(err) method.

  1. c.Error() error
  1. func main() {
  2. app := fiber.New()
  3. app.Post("/api/register", func (c *fiber.Ctx) {
  4. if err := c.JSON(&User); err != nil {
  5. c.Next(err)
  6. }
  7. })
  8. app.Get("/api/user", func (c *fiber.Ctx) {
  9. if err := c.JSON(&User); err != nil {
  10. c.Next(err)
  11. }
  12. })
  13. app.Put("/api/update", func (c *fiber.Ctx) {
  14. if err := c.JSON(&User); err != nil {
  15. c.Next(err)
  16. }
  17. })
  18. app.Use("/api", func(c *fiber.Ctx) {
  19. c.Set("Content-Type", "application/json")
  20. c.Status(500).Send(c.Error())
  21. })
  22. app.Listen(1337)
  23. }