Skip to content

fix: surface Graph API error body in GraphError#524

Merged
heyitsaamir merged 7 commits intomainfrom
fix/graph-error-response-body
Apr 15, 2026
Merged

fix: surface Graph API error body in GraphError#524
heyitsaamir merged 7 commits intomainfrom
fix/graph-error-response-body

Conversation

@heyitsaamir
Copy link
Copy Markdown
Collaborator

@heyitsaamir heyitsaamir commented Apr 14, 2026

Summary

  • Add GraphError class to packages/graph that extracts the Graph API response body (error code + message) from AxiosErrors
  • Wrap Client.call() with error handling so Graph errors produce readable messages like Graph GET /chats/.../messages failed (403): Insufficient privileges to complete the operation. instead of just AxiosError: Request failed with status code 403
  • GraphError exposes statusCode, code, and full body for programmatic error handling

Test plan

  • Added test for Graph API error with standard { error: { code, message } } body
  • Added test for non-standard error body (e.g. plain string)
  • Existing tests pass (59/59) — non-Axios errors still propagate unchanged

AxiosErrors from Graph API calls only showed status codes, with the actual
error body (code, message) hidden behind `[Object]`. Add a GraphError class
that extracts and formats the response body for readable error messages.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 14, 2026 20:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a typed GraphError to surface Graph API response details when Axios-based calls fail, improving debuggability and enabling programmatic handling.

Changes:

  • Introduced GraphError (statusCode, code, body) and message formatting using Graph error payloads.
  • Wrapped Client.call() in Axios-aware error handling to throw GraphError on HTTP failures.
  • Added Jest coverage for standard and non-standard Graph error bodies.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/graph/src/index.ts Adds GraphError and converts Axios response failures into GraphError from Client.call()
packages/graph/src/index.spec.ts Adds tests asserting GraphError payload extraction and messaging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/graph/src/index.ts Outdated
Comment thread packages/graph/src/index.ts Outdated
Comment thread packages/graph/src/index.ts Outdated
Comment thread packages/graph/src/index.ts
Address review feedback:
- Rename constructor param from `path` to `url` to match what's actually passed
- Pass original AxiosError as `cause` to preserve stack/request metadata

Co-Authored-By: Claude <noreply@anthropic.com>
@heyitsaamir heyitsaamir requested a review from Copilot April 14, 2026 20:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/graph/src/index.ts
Comment thread packages/graph/src/index.spec.ts Outdated
Copy link
Copy Markdown
Contributor

@Jesperholmbergmsft Jesperholmbergmsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it!

- Fix import order (axios before @microsoft/teams.common)
- Widen cause param from Error to unknown to match ErrorOptions
- Use rejects matcher instead of try/catch+fail in tests

Co-Authored-By: Claude <noreply@anthropic.com>
heyitsaamir and others added 2 commits April 14, 2026 18:05
…ilds

The `import { isAxiosError } from 'axios'` pulled the entire axios lib
(including Node-only modules like stream, zlib) into the graph bundle,
breaking the tab example's Vite browser build. Replace with inline check.

Co-Authored-By: Claude <noreply@anthropic.com>
heyitsaamir and others added 2 commits April 14, 2026 21:00
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@heyitsaamir heyitsaamir merged commit ee0af30 into main Apr 15, 2026
7 checks passed
@heyitsaamir heyitsaamir deleted the fix/graph-error-response-body branch April 15, 2026 06:08
heyitsaamir added a commit that referenced this pull request Apr 16, 2026
## Summary
- Merges all changes from `main` since v2.0.7 into `release`
- Sets `version.json` to stable `2.0.8`

### What's included
- **feat:** Sovereign cloud support (GCCH, DoD, China) (#500)
- **feat:** Add missing endpoints — Paged Members, Meeting Notifications
& client gaps (#516)
- **feat:** Graceful stream cancellation on 403 (#513)
- **feat:** GitHub issue analysis → Teams notification workflow (#517)
- **fix:** Improve error message when app credentials are missing (#527)
- **fix:** Surface Graph API error body in GraphError (#524)
- **fix:** Resolve missing deps, broken JSON, type errors, and typos in
CLI templates (#521)
- **fix:** Drain entire queue per flush cycle (#520)
- **fix:** Merge User-Agent headers when cloning HTTP client (#508)
- Dependency bumps: hono, axios, vite, @hono/node-server

## Post-merge
1. Trigger the [release
pipeline](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_build?definitionId=52&_a=summary)
for `release` with **Public** publish type
2. Bump `version.json` on `main` to `2.0.9-preview.{height}`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

3 participants