Better error handling when sending bad responses to clients