Skip to content

Conversation

dominicfallows
Copy link

Summary

Improve error handling and logging for Microsoft Graph API token acquisition in both the controller and service layers. The changes provide more detailed error context, making debugging easier and improving observability.

Error handling and logging enhancements:

  • In AuthController.js, the graphTokenController now logs a structured error object with message, details, original error message, and stack trace for failed Graph API token requests.

  • In GraphTokenService.js, a new parseResponseBody utility function is introduced to robustly parse error response bodies, handling both JSON and string formats.

  • The getGraphApiToken function now extracts and logs more granular error information, including status code, error description, and the parsed response body. It also wraps the original error in a new error object with additional details for better propagation and debugging.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

With debugging enabled, and Microsoft Graph setup configured in env vars, we see detailed error logs on problems, for example missing scope in the token.

Test Configuration:

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant