Search code examples
microsoft-graph-apionedrive

OneDrive file download returns 95 byte content


Not sure exactly since when, but some files that are downloaded from OneDrive by Graph API returns 95-byte contents. And it's all like following.

{"error":{"code":"serviceNotAvailable","message":"Service unavailable","retryAfterSeconds":30}}

More precisely, the ordinary file download for the file-location returned by the following API has the issue. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get_content?view=odsp-graph-online

It seems the server returns the error as contents, not by returning HTTP errors. This is related to the 'data-integrity', so I think you should always return HTTP errors.


Solution

  • It turned out that the C# HttpClient throws TaskCanceledException in an AggregateException when timeout happens.

    So it's not the API problem itself but needs extra care when dealing with HttpClient.

    HttpClient needs to be revised to throw HttpRequestException or some other HTTP related exception, other than throwing TaskCanceledException.