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

Allow for custom error message during BARF recovery #18

Open
Folakuku opened this issue Sep 28, 2023 · 0 comments
Open

Allow for custom error message during BARF recovery #18

Folakuku opened this issue Sep 28, 2023 · 0 comments

Comments

@Folakuku
Copy link

Folakuku commented Sep 28, 2023

Either directly pass a RecoveryMessage or pass a RecoveryHandler, a function that gives you access to the panic error, manipulate it as needed, maybe even send an alert somewhere and then return a response string that's sent as the server response.

Here's sample use case

        // create server
	if err := barf.Stark(barf.Augment{
		Logging:        barf.Allow(), // enable request logging
		Recovery:       barf.Allow(), // enable panic recovery so barf returns a 500 error instead of crashing
                RecoveryHandler: func (err error) string {
                        return err.String() 
                },
                RecoveryMessage: "Something went wrong",
	}); err != nil {
		barf.Logger().Error(err.Error())
		os.Exit(1)
	}
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

No branches or pull requests

1 participant