properly handle utf-8 exceptions when building error response