elixir-maru / maru

Elixir RESTful Framework
https://maru.readme.io
BSD 3-Clause "New" or "Revised" License
1.32k stars 84 forks source link

No way to report an error in custom type parsing #114

Open mikebveil opened 5 years ago

mikebveil commented 5 years ago

We're constructing a custom Maru type (use Maru.Type), and in our parse/2 function we do certain validations that may fail. But there doesn't seem to be a way to report validation errors back to the HTTP client. Returning {:error, …} from parse/2 doesn't trigger any special behavior, so we currently raise a custom exception. Looking at runtime.ex, it looks like the exception is handled and rethrown without any of the original exception data. So that when our code tries to rescue from Maru.Exceptions.Validation, we don't have enough context to produce a specific client response.

Is there a solution to this I'm missing? If not, would you accept a patch to include "inner exception" data in Maru.Exceptions.Validation?

mikebveil commented 5 years ago

Above commit is to the v0.11 branch because our dependencies are frozen currently. But I would port it to master before applying to elixir-maru/maru.