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

Some example how to return all errors as JSON/HTTP code? #1333

Closed
bapcyk opened this issue Sep 1, 2020 · 3 comments
Closed

Some example how to return all errors as JSON/HTTP code? #1333

bapcyk opened this issue Sep 1, 2020 · 3 comments

Comments

@bapcyk
Copy link

bapcyk commented Sep 1, 2020

I am on LTS-16.4. So, servant-server is 0.16.2. I want to return errors like:

  1. unexpected runtime exception like divison on 0, error call and similar as HTTP 500 and some JSON object
  2. errors thrown by me as HTTP , JSON object
  3. errors from REST endpoints parsing procedure (like wrong URL, missing part of the endpoint, and similar) as some HTTP code and JSON object

and I need to do it in a simple and general way, so not to do 3 different approaches for these 3 cases, but the one simple general solution. I know how to achieve 2, but I don't know how to do 1 and 2. I don't know how https://docs.servant.dev/en/stable/cookbook/custom-errors/CustomErrors.html is relevant, but as I understood already, the servant still is not for production usage , because of breaking changes: I cannot find any Servant.Server.Internal.ErrorFormatter in my 0.16.2 version... So, my question is simple: is any adequate way to do it in servant: I suppose such obvious and simple task should be solved a long time ago and maybe it is just not described in the tutorials and documentation? If it is, then please, add some description in the tutorial - I cannot find any answer for all 3 cases in the Web, if no such a solution at all, please, write somewhere in the documentation that servant still is not for production usage.

@fisx
Copy link
Member

fisx commented Sep 1, 2020

will be fixed by #1314 has been fixed in 0.18.

@bapcyk
Copy link
Author

bapcyk commented Sep 2, 2020

OK, if it's planned, then I will close the issue.

The last question: is it possible to do it today in some simple way like a temporary workaround?

@bapcyk bapcyk closed this as completed Sep 2, 2020
@fisx
Copy link
Member

fisx commented Sep 2, 2020

Sorry, that was sloppy reading on my side: you already found the solution to your issue, you just need to upgrade servant. 0.16 is quite outdated. I updated my earlier comment.

To render 5xx errors I would go for a middleware. Feel free to open another issue to extend https://docs.servant.dev/en/stable/cookbook/custom-errors/CustomErrors.html; my feeling is we don't want to do that, but I would have to think about it more.

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