Skip to content

chore(advanced-wallets): improve error handling#67

Closed
pranavjain97 wants to merge 1 commit into
masterfrom
WP-5260-api-error-handling
Closed

chore(advanced-wallets): improve error handling#67
pranavjain97 wants to merge 1 commit into
masterfrom
WP-5260-api-error-handling

Conversation

@pranavjain97

Copy link
Copy Markdown
Contributor

Ticket: WP-5260

@mohammadalfaiyazbitgo

Copy link
Copy Markdown
Contributor

@claude Review this pr

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances error handling across the service by standardizing API error mappings, extending response schemas, and aligning tests with the new status codes.

  • Introduces uniform handling for ApiResponseError and generic errors in responseHandler.ts
  • Adds 400 and 404 response definitions in multiple API spec files
  • Updates consolidate handler to return 202 for partial success and throws EnclavedError in the client
  • Adjusts tests to expect the new status codes and error shapes

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/shared/responseHandler.ts Reworked error branches: handle ApiResponseError, generic 4xx+, and <400 responses
src/enclavedBitgoExpress/routers/enclavedApiSpec.ts Added 400/404 response schemas to all endpoints
src/api/master/routers/masterApiSpec.ts Extended endpoints with 400/404, adjusted recipients type
src/api/master/routers/healthCheck.ts Added 404 schema for health endpoints
src/api/master/handlers/handleConsolidate.ts Changed all-failed status from 400 to 500, partial from 202
src/api/master/clients/enclavedExpressClient.ts Wraps thrown errors as EnclavedError with a 500 status
Multiple test files under src/__tests__ Updated expected status codes (202, 404) and error shapes
Comments suppressed due to low confidence (3)

src/enclavedBitgoExpress/routers/enclavedApiSpec.ts:322

  • [nitpick] The constant name EnclavedAPiSpec uses inconsistent casing (APi). It should be renamed to EnclavedApiSpec for clarity and consistency.
        },

src/api/master/routers/masterApiSpec.ts:133

  • The spec still lists 400 for "All failed" responses, but the handler now returns 500 in that case. Update the spec to match the implementation or revert the handler to 400.
  400: t.any, // All failed

src/enclavedBitgoExpress/routers/enclavedApiSpec.ts:42

  • A 404 response schema was added here, but there are no tests covering this error path. Consider adding tests to verify the 404 error format and status.
  404: t.type({

@@ -61,7 +61,7 @@ export async function handleConsolidate(
msg = `Consolidations failed: ${result.failure.length} and succeeded: ${result.success.length}`;
} else {
// All failed

Copilot AI Jul 15, 2025

Copy link

Choose a reason for hiding this comment

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

This comment implies a 400 status for all failures, but the code now sets status = 500. Update the comment to reflect that a 500 is returned on complete failure.

Suggested change
// All failed
// All consolidations failed, returning status 500

Copilot uses AI. Check for mistakes.
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