Open dblock opened 8 years ago
rescue_from
. I think we should mostly catch similar exceptions by rescue_from
and return custom error to client. As a result I raise exceptions instead of rendering an error page.
Plug 1.2.0 released recently and I have a plan to show plug error page by default for :dev
environment.Grape has error formatters and default handling. It feels like the default for JSON should return a JSON error. This would be much more convenient and logical IMO, there's no user out there who wants a 500 with an HTML page that gives you a call stack and an exception when you supply an invalid parameter for example.
InvalidFormatter is just a poorly worded name I think. It says "the formatter is invalid", probably meant to say "the format is invalid"?
So the only thing I should do is change name and printed message of the exception module? For example:
** (Maru.Exceptions.InvalidFormat) :token is required.
or
** (Maru.Exceptions.InvalidFormat) :age is illegal.
2) Shouldn't this be handled and turned into a 400 Bad Request error and not raise?
I'll think more about how to handle it by default.
Yes on the exception name it would be a start.
I would namespace the parameter exceptions, maybe Maru.Exceptions.Validations.InvalidFormat
and such? And they all would inherit form Maru.Exceptions.Validations.ValidationError
so that they can be caught together?
There's no inherit
in elixir world, I must remake namespace in elixir way.
A POST request to an API with
requires :token
yields this without a token:Seems like there're two problems.
1) This is not a formatter error, it's some kind of missing or invalid parameter error. 2) Shouldn't this be handled and turned into a 400 Bad Request error and not raise?