Fixed the handling of error responses