Skip to content

fix: improve error handling for 404s to use UserInputError #371

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

Closed
wants to merge 1 commit into from

Conversation

dcramer
Copy link
Member

@dcramer dcramer commented Jul 10, 2025

  • Add reusable error handling utilities in api-utils.ts
  • Convert 404 API errors to UserInputError with clear messages
  • Handle HTML error pages from server errors separately
  • Update get-issue-details and update-issue tools to use new pattern
  • Add comprehensive tests for error handling utilities

This ensures users get helpful error messages when they provide invalid issue IDs instead of seeing raw API errors.

🤖 Generated with Claude Code

- Add reusable error handling utilities in api-utils.ts
- Convert 404 API errors to UserInputError with clear messages
- Handle HTML error pages from server errors separately
- Update get-issue-details and update-issue tools to use new pattern
- Add comprehensive tests for error handling utilities

This ensures users get helpful error messages when they provide invalid
issue IDs instead of seeing raw API errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Regex Bug Affects API Error Handling

The regex /^get|update/ in handleApiError is incorrect. It matches "get" at the beginning OR "update" anywhere in the string, but should match "get" OR "update" only at the beginning. The correct regex is /^(get|update)/. This flaw could lead to incorrect resourceType derivation for operations where "update" is not at the start (e.g., "analyzeUpdateData" would incorrectly become "analyzeData").

packages/mcp-server/src/tools/utils/api-utils.ts#L77-L78

context.resourceType ||
context.operation.replace(/^get|update/, "").toLowerCase();

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@dcramer dcramer closed this Jul 10, 2025
Comment on lines +76 to +78
const resourceType =
context.resourceType ||
context.operation.replace(/^get|update/, "").toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

The regex pattern /^get|update/ will match either "get" at the start of a string OR "update" anywhere in the string, which produces incorrect results. For example, with "getEvent", it removes only "get" leaving "Event", then lowercases to "event" (which happens to work), but "updateEvent" would become "event" (correct) while "getUpdateInfo" would become "updateInfo" (incorrect).

Consider using /^(get|update)/ to properly group the alternation, ensuring only prefixes are matched. Alternatively, a more explicit mapping approach might be more maintainable for future operation types:

const operationToResourceType = {
  getIssue: 'issue',
  updateIssue: 'issue',
  getEvent: 'event',
  // other mappings...
};

const resourceType = context.resourceType || 
  operationToResourceType[context.operation] || 
  context.operation.toLowerCase();
Suggested change
const resourceType =
context.resourceType ||
context.operation.replace(/^get|update/, "").toLowerCase();
const resourceType =
context.resourceType ||
context.operation.replace(/^(get|update)/, "").toLowerCase();

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

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