Handle errors in API call separately to errors with file writing.
Handle errors in API call separately to errors with file writing.