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

anyhow demo and how to handle error #12

Closed
siwilizhao opened this issue Apr 16, 2021 · 1 comment
Closed

anyhow demo and how to handle error #12

siwilizhao opened this issue Apr 16, 2021 · 1 comment

Comments

@siwilizhao
Copy link
Contributor

No description provided.

@chrislearn
Copy link
Member

chrislearn commented Apr 17, 2021

I have created an example: https://github.com/salvo-rs/salvo/blob/master/examples/handle_error.rs

Current implementation for anyhow is too simple, just return 500 error, we may let it more flexible in future.

If you want handle your custom error, just implement Writer trait for your custom error.

In writer function, you can access request, deport and response, so you can do something like: just show error details to internal users or in debug mode.

run command to view this example:

cargo run --example handle_error

and then view this two page in your browser:
http://localhost:7878/custom
http://localhost:7878/anyhow

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

2 participants