devinus/poison — pull request #2 by fishcakez (2014-08-10 17:53:24+00:00)
Title: Improve error handling

`Posion.encode/2` currently rescues all exceptions. This means that it can catch "code bugs" when we only want it to catch "data bugs". Therefore it should only rescue encode errors.

The situation was also awkward because the errors returned could not easily be pattern matched on because the error information was a string. Including a string in this way is only useful if the string is going to be displayed to an end-user. It is likely that a custom error would be shown - that did not include the string in the error tuple. The errors now return a usable type that can be pattern matched on if required.

I have made the error returns consistent. This means a slightly different return for `Poison.decode/2`. I did this because it is awkward to have an error tuple that can be contain 2 or 3 elements.

```elixir
case Posion.decode(data) do
{:ok, term} -> do_stuff(term)
{:error, _} -> send_error()
end
```