fix content negotiation in error handling (closes #398)