Hello @Giorgio Sfiligoi, Since you're using the Microsoft Graph SDK, you're likely expecting exceptions like ODataError
or ServiceException
when something goes wrong. However, if the internet connection is lost during the request, the SDK throws an HttpRequestException
instead — and in this case, StatusCode
will be null
, and HttpRequestError
is marked as Unknown
.
- ODataError is thrown only when the Microsoft Graph API returns a valid HTTP response that includes a structured OData error in the body — for instance, errors like
400 Bad Request
,403 Forbidden
, or404 Not Found
. - ServiceException is a more general error from the Graph SDK that wraps any error responses received from the API. It includes useful details like the HTTP status code and error message.
- HttpRequestException, on the other hand, comes from the underlying
System.Net.Http
layer. It’s thrown when the request fails before it ever reaches the Microsoft Graph service — for example, due to network issues, DNS problems, or no internet connection. Since there's no HTTP response in these cases, there’s no status code available.
So, in your case, ODataError
wasn’t throw because both ODataError
and ServiceException
depend on the existence of a valid HTTP response from Microsoft Graph. If the network is disconnected and the request can’t reach the service at all, no response is received — and therefore, no structured error can be parsed. ODataError
is typically used when there is a response body to analyze, which doesn't apply in this scenario.
Hence, The HttpRequestException
is the correct exception to handle in this scenario, and it indicates a problem with the request itself rather than a server-side error.
Hope this clarifies things!
If this answer was helpful, please click "Accept the answer" and mark Yes
, as this can help other community members.
If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.