-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
How can I handle global errors like express? #184
Comments
options.onError and you can still use custom server too, see options.server |
Hello, thanks for your reply. The main issue here is that it is catching my errors but the server is crashing and I can not find any way to prevent server crashes. I also attempted to run this code, but it still generates errors and crashes the server. If you are wondering about my code, it is here but I can not hit the main route and it will always give me an error hanling route in response. If I am doing something wrong, please correct me. |
export const handleErr = (req, res, err) => {
res.statusCode = 500;
res.setHeader("content-type", "application/json").end(
jsonStringify({
success: false,
msg: "something went wrong on server",
data: {},
})
);
}; This means every route is going to reply with a |
Unfortunately, I can not figure out how to implement this on my own, so it would be great if you could add an example of how to handle errors and send error responses with custom json. If you could add an example, it would be much help. |
12 is an example. You copied it incorrectly |
Thank you for pointing it out. And for your reply, I figured it out and implemented it in the code. |
I want to handle global errors like express, but I can not find any way to handle global errors in the current version of polka.
All I can find is this thread, but it is not supported in recent versions of polka since we can not create a custom server with http.
#12 (comment)
Is it possible to handle global errors like express?
The text was updated successfully, but these errors were encountered: