Response error handling in api.py