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

On failure to unmarshal msgraph API error, log whole response body #254

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

mickmister
Copy link
Contributor

@mickmister mickmister commented Apr 13, 2023

Summary

For context, please see https://community.mattermost.com/core/pl/a7m4w3tbufgzdj1trqkt3mj3tw

Here is the error we're currently getting when trying to create a superuser token for the status sync feature:

Error during user status sync job. err=not able to filter the super user client: msgraph GetSuperuserToken: status: 400 Bad Request: json: cannot unmarshal string into Go struct field ErrorResponse.error of type msgraph.ErrorObject

We're receiving a 400 Bad Request from Microsoft's API, with a response body that does not match the expected ErrorObject struct. Since the Unmarshal fails, we don't have any other context for what actual error occurred.

This PR makes it so we log the response body in the case that this unmarshal fails.


This error is originally happening here on line 99:

errResp := msgraph.ErrorResponse{Response: resp}
err = json.Unmarshal(responseData, &errResp)
if err != nil {
return responseData, errors.WithMessagef(err, "status: %s", resp.Status)
}
if err != nil {
return responseData, err
}
return responseData, &errResp

Ticket Link

https://mattermost.atlassian.net/browse/MM-52156

@mickmister mickmister requested review from trilopin and hanzei April 13, 2023 17:36
@mickmister mickmister changed the title On failure to unmarshal msgraph API error, log response body On failure to unmarshal msgraph API error, log whole response body Apr 13, 2023
@mickmister mickmister merged commit f1a4aa0 into master Apr 13, 2023
@mickmister mickmister deleted the print-error-response branch April 13, 2023 19:08
@mickmister mickmister mentioned this pull request Apr 13, 2023
@hanzei hanzei added the 4: Reviews Complete All reviewers have approved the pull request label Apr 18, 2023
trilopin added a commit that referenced this pull request Apr 27, 2023
* master:
  bump version to 1.2.1 (#255)
  print response if fail to unmarshal error (#254)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants