How to catch "The remote server returned an error: (401) Unauthorized."
I need to catch this specific exception to do another action.
The problem is, I'm not sure how to recognize it.
Right now, I'm using
catch (Exception ex)
{
}
but the exception "The remote server returned an error: (401)
Unauthorized." appears inside the "InnerException" and the "Message", so
no code or anything.
How can I track this specific exception?
I am using GoogleDrive SDK if it's relevant.
Tried to use this:
catch (GoogleApiRequestException e) {
if (e.HttpStatusCode == HttpStatusCode.Unauthorized) {
// Credentials have been revoked.
// TODO: Redirect the user to the authorization URL.
throw new NotImplementedException();
}
}
But e.HttpStatusCode was 0, so it didn't recognize it.
No comments:
Post a Comment