chore(advanced-wallets): improve error handling#67
Closed
pranavjain97 wants to merge 1 commit into
Closed
Conversation
Contributor
|
@claude Review this pr |
There was a problem hiding this comment.
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
ApiResponseErrorand generic errors inresponseHandler.ts - Adds
400and404response definitions in multiple API spec files - Updates consolidate handler to return
202for partial success and throwsEnclavedErrorin 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
EnclavedAPiSpecuses inconsistent casing (APi). It should be renamed toEnclavedApiSpecfor clarity and consistency.
},
src/api/master/routers/masterApiSpec.ts:133
- The spec still lists
400for "All failed" responses, but the handler now returns500in that case. Update the spec to match the implementation or revert the handler to400.
400: t.any, // All failed
src/enclavedBitgoExpress/routers/enclavedApiSpec.ts:42
- A
404response schema was added here, but there are no tests covering this error path. Consider adding tests to verify the404error 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 | |||
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: WP-5260