Fix content negotiation in error handling

Fixes #398.
Done.