Better handling of errors returned by the API