Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override Message property of ODataError to show error code and error message #2094

Closed
MartinM85 opened this issue Aug 24, 2023 · 4 comments · Fixed by #2130
Closed

Override Message property of ODataError to show error code and error message #2094

MartinM85 opened this issue Aug 24, 2023 · 4 comments · Fixed by #2130

Comments

@MartinM85
Copy link
Contributor

Since SDK v5 has been released I see on StackOverflow and Microsoft Q&A that many developers are confused about ODataError.

When the Graph API service returns the ODataError error and the Message property displays text Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown. This description is useless for the developers.

The message should show at least the error code and the error message.

Describe the solution you'd like
I would suggest to generate overriden Message property of the ODataError

public class ODataError : ApiException, IAdditionalDataHolder, IBackedModel, IParsable
{
    ...
    public override string Message => $"{Error?.Code}:{Error?.Message}";
    ...
}

Describe alternatives you've considered
Another alternative was to override ToString method

Additional context
Add any other context or screenshots about the feature request here.

@MartinM85 MartinM85 changed the title Generate ToString method for ODataError Override Message property for ODataError to show error code and error message Aug 24, 2023
@MartinM85 MartinM85 changed the title Override Message property for ODataError to show error code and error message Override Message property of ODataError to show error code and error message Aug 24, 2023
@macwier
Copy link

macwier commented Sep 19, 2023

How does the PR fix this issue?

I still see e.g. The server returned an unexpected status code and no error factory is registered for this code: 400 without seeing the body of the error in the exception.
Or was this not supposed to fix and i should create separate issue?

@andrueastman
Copy link
Member

Any chance you can share the sample code when the error is thrown @macwier ?

@macwier
Copy link

macwier commented Sep 20, 2023

            var users = new List<User>();

            var response = await GraphServiceClient.Groups[groupId].TransitiveMembers
                .GraphUser
                .GetAsync(x => x.QueryParameters.Select = new[]
                    { "id", "displayName", "mail", "otherMails", "userPrincipalName", "accountEnabled", "proxyAddresses", "officeLocation" });
            var pageIterator = PageIterator<User, UserCollectionResponse>.CreatePageIterator(
                GraphServiceClient, response, (user) => { users.Add(user); return true; });
            await pageIterator.IterateAsync();

            return users;

The problem is that this happens only for one particular group (we use that code on multiple AADs and all works ok, except one particular group within one AAD). I know that the group has members, but I don't actually have access to authorize as the service principal and debug the code (this happens in production). So the problem is, I'm getting an error, but I don't know what it is about, beside it being http status 400.

I was hoping that this would give me the body of the response in the logs (i.e. when doing .ToString() on the ApiException), but looking at the code, it doesn't seem like it.

@andrueastman
Copy link
Member

This is a separate issue. Created microsoftgraph/msgraph-sdk-dotnet-core#728 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants