Added response code error handling so exceptions become responses with errors