Dancer2
Dancer2 copied to clipboard
Allow send_error to send different content types
In applications where there are routes outputting json and html functions like send_as
make that work without too much of a problem. send_error
appears to have all the logic to deal with a serializer, but it could do with a way of asking for a different one so that errors come out in a consistent format with the rest of the request rather than what the global application is configured for.
It looks relatively simple to implement assuming a reasonable syntax can be agreed upon for the helper. I'd be willing to create a pull request but I figured it was best to check it wasn't going to get shot down before doing so.
This looks potentially useful, say with a send_error_as
keyword.
Note that send_as
started out as a plugin; which helped us iron out the syntax. You may want to consider the same approach for this.
You would need to refactor the logic in send_as
so it isn't repeated.