Better error handling for the API.