You encountered 500 error response which means that an expected error occured while processing the request. Based on the Official Google Documentation, the suggested action is to use exponential backoff, Exponential backoff is a standard error handling strategy for network applications in which the client periodically retries a failed request over an increasing amount of time. If a high volume of requests or heavy network traffic causes the server to return errors, exponential backoff may be a good strategy for handling those errors. Conversely, it is not a relevant strategy for dealing with errors unrelated to rate-limiting, network volume or response times, such as invalid authorization credentials or file not found errors.
Used properly, exponential backoff increases the efficiency of bandwidth usage, reduces the number of requests required to get a successful response, and maximizes the throughput of requests in concurrent environments.
Here's a related SO ticket which discuss 500 internal error with Google Drive API: Frequently http 500 internal error with google drive API drive.files.get