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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Recover #128

Merged
merged 3 commits into from
Feb 12, 2020
Merged

Add Recover #128

merged 3 commits into from
Feb 12, 2020

Conversation

Fenny
Copy link
Member

@Fenny Fenny commented Feb 12, 2020

#126

//
// Recover ( disabled by default, unless a custom Recover handler is set )
// We might enable Recover by default with "500 Internal Server Error" in the future
//
func main() {
  app := fiber.New()
  app.Get("/", func(c *fiber.Ctx) {
    panic("I panic")
  })
  app.Recover(func(c *fiber.Ctx) {
    c.Status(500).Send(c.Error()) // => 500 "I panic"
  })
  app.Listen(3000)
}
//
// Context error
//
package main

import "github.com/gofiber/fiber"

func main() {
  app := fiber.New()
  app.Post("/api/register", func (c *fiber.Ctx) {
    if err := c.JSON(&User); err != nil {
      c.Next(err)
    }
  })
  app.Get("/api/user", func (c *fiber.Ctx) {
    if err := c.JSON(&User); err != nil {
      c.Next(err)
    }
  })
  app.Put("/api/update", func (c *fiber.Ctx) {
    if err := c.JSON(&User); err != nil {
      c.Next(err)
    }
  })
  app.Use("/api", func(c *fiber.Ctx) {
    c.Set("Content-Type", "application/json")
    c.Status(500).Send(c.Error())
  })
  app.Listen(1337)
}

@Fenny Fenny merged commit 8ab42e2 into gofiber:master Feb 12, 2020
@1995parham
Copy link

@Fenny Thanks 🙌 I will use it in my project!

@koddr
Copy link

koddr commented Feb 12, 2020

@1995parham it would be great to some feedback after using and testing this features 👍

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

Successfully merging this pull request may close these issues.

3 participants