-
-
Notifications
You must be signed in to change notification settings - Fork 275
feat: add degradedType and retriedError to degraded events
#7988
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9ae4a22
feat: add degradedType and retriedError to degraded events
cryptodev-2s 9848b08
refactor: extract shared helpers for retry filter and error classific…
cryptodev-2s f29efd1
refactor: move classification to create-network-client, rename types …
cryptodev-2s 8f4342f
fix: remove useless line return
cryptodev-2s f105869
fix: remove useless as const cast
cryptodev-2s 9a8ab31
fix: remove useless rpc-service-requestable change
cryptodev-2s 1821148
fix: remove useless line return
cryptodev-2s c87f409
refactor: rename to non_successful_http_status, return unknown, expor…
cryptodev-2s f75d349
fix: FetchError from node-fetch
cryptodev-2s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
61 changes: 61 additions & 0 deletions
61
packages/network-controller/src/create-network-client-tests/classify-retry-reason.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { HttpError } from '@metamask/controller-utils'; | ||
| import { FetchError } from 'node-fetch'; | ||
|
|
||
| import { classifyRetryReason } from '../create-network-client'; | ||
|
|
||
| describe('classifyRetryReason', () => { | ||
| it('returns "connection_failed" for FetchError connection failures', () => { | ||
| const error = new FetchError( | ||
| 'request to https://example.com failed, reason: connect ECONNREFUSED', | ||
| 'system', | ||
| ); | ||
| expect(classifyRetryReason(error)).toBe('connection_failed'); | ||
| }); | ||
|
|
||
| it('returns "connection_failed" for TypeError network errors', () => { | ||
| const error = new TypeError('Failed to fetch'); | ||
| expect(classifyRetryReason(error)).toBe('connection_failed'); | ||
| }); | ||
|
|
||
| it('returns "response_not_json" for SyntaxError (invalid JSON)', () => { | ||
| const error = new SyntaxError('Unexpected token < in JSON'); | ||
| expect(classifyRetryReason(error)).toBe('response_not_json'); | ||
| }); | ||
|
|
||
| it('returns "response_not_json" for "invalid json" error messages', () => { | ||
| const error = new Error('invalid json response body'); | ||
| expect(classifyRetryReason(error)).toBe('response_not_json'); | ||
| }); | ||
|
|
||
| it.each([502, 503, 504])( | ||
| 'returns "non_successful_http_status" for %i errors', | ||
| (status) => { | ||
| expect(classifyRetryReason(new HttpError(status))).toBe( | ||
| 'non_successful_http_status', | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it('returns "timed_out" for ETIMEDOUT errors', () => { | ||
| const error = new Error('timed out'); | ||
| Object.assign(error, { code: 'ETIMEDOUT' }); | ||
| expect(classifyRetryReason(error)).toBe('timed_out'); | ||
| }); | ||
|
|
||
| it('returns "connection_reset" for ECONNRESET errors', () => { | ||
| const error = new Error('connection reset'); | ||
| Object.assign(error, { code: 'ECONNRESET' }); | ||
| expect(classifyRetryReason(error)).toBe('connection_reset'); | ||
| }); | ||
|
|
||
| it('returns "unknown" for unrecognized Error instances', () => { | ||
| expect(classifyRetryReason(new Error('something else'))).toBe('unknown'); | ||
| }); | ||
|
|
||
| it('returns "unknown" for non-Error values', () => { | ||
| expect(classifyRetryReason('a string')).toBe('unknown'); | ||
| expect(classifyRetryReason(42)).toBe('unknown'); | ||
| expect(classifyRetryReason(null)).toBe('unknown'); | ||
| expect(classifyRetryReason(undefined)).toBe('unknown'); | ||
| }); | ||
| }); |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.