I have this code running iteratively in a loop to gather chat objects associated with each Azure user in our tenant:
var nextPageRequest = new ChatsRequestBuilder(nextPageLink, appClient.RequestAdapter);
chatPage = await nextPageRequest.GetAsync();
In the above code, appClient is the GraphServiceClient object.
Sometimes, this request fails, but not in any pattern I can discern. The error I usually get first is simply 'UnknownError' and the error code is 502 Bad Gateway. Subsequent calls with this same line of code generates a different error: PreconditionFailed. Requested API is not support in an application-only context.
This does not always occur in my loop, but it usually does. My initial presumption is that I'm being rate limited, however I don't have any direct evidence of that. If that's the case, then once rate limiting kicks in, the subsequent error would suggest that my authentication was revoked as part of that rate limiting.
My understanding is that the GraphServiceClient is supposed to deal with rate limiting without any input from me, but if that's not the case, then how would I go about detecting when I'm about to be rate limited?