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

Error handling #39

Closed
lpil opened this issue Feb 13, 2018 · 10 comments
Closed

Error handling #39

lpil opened this issue Feb 13, 2018 · 10 comments

Comments

@lpil
Copy link
Contributor

lpil commented Feb 13, 2018

Hello!

Is there a recommended way of handling errors so that an application using Elli serves 500 with a suitable body whenever the handler crashes?

Thanks,
Louis

@yurrriq
Copy link
Member

yurrriq commented Mar 1, 2018

@lpil
Copy link
Contributor Author

lpil commented Mar 1, 2018

At my company we have a specific format for error bodies.

Currently I'm catching at exceptions and thrown values in the callback and returning said body. Is this the recommended way to do this? :)

@yurrriq
Copy link
Member

yurrriq commented Mar 1, 2018

I would suggest to use postprocess/3 something like this:

postprocess(Req, {500, Body}, Config) ->
  custom_error(Req, [], Config);
postprocess(Req, {500, Headers, Body}, Config) ->
  custom_error(Req, Headers, Config);
postprocess(_, Res, _) ->
  Res.


custom_error(Req, Headers, Config) ->
  {500, Headers, CustomBody}.

@lpil
Copy link
Contributor Author

lpil commented Mar 1, 2018

Wonderful, thank you.

I see that postprocess isn't part of the elli_handler behaviour. I presume it goes in the same module?

@yurrriq
Copy link
Member

yurrriq commented Mar 1, 2018

Yeah! I'd love to codify an elli_middleware behaviour.

@lpil
Copy link
Contributor Author

lpil commented Mar 1, 2018

That would be great. It's quite unclear how to use the middlewear features at the moment I think.

@yurrriq
Copy link
Member

yurrriq commented Mar 6, 2018

This seems pretty related to elli-lib/elli_fileserve#7 and #3. Also note that I've spec'd out init/2, preprocess/2 and postprocess/3 as optional callbacks in elli_handler in 71a7c9a.

@lpil
Copy link
Contributor Author

lpil commented Mar 7, 2018

That's much clearer for me, thanks :)

@yurrriq
Copy link
Member

yurrriq commented Mar 8, 2018

Great! I’ll publish a new release in the next few days.

@yurrriq
Copy link
Member

yurrriq commented Mar 13, 2018

https://hex.pm/packages/elli/2.1.2

Feel free to re-open if need be, but I'm closing this for now.

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