Skip to content

Commit

Permalink
Sm/mdapi-fault-handler (#642)
Browse files Browse the repository at this point in the history
* feat: handle transient mdapi error

* chore: auto-update metadata coverage in METADATA_SUPPORT.md

* test: mdapi error handling
  • Loading branch information
mshanemc authored Jun 7, 2022
1 parent 69b53ea commit 6e778e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ v56 introduces the following new types. Here's their current level of support
|:---|:---|:---|
|AccountingSettings|||
|CollectionsDashboardSettings|||
|CustomizablePropensityScoringSettings|||
|MfgServiceConsoleSettings|||
|OauthOidcSettings|||

## Additional Types

Expand Down
7 changes: 7 additions & 0 deletions src/client/metadataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ export abstract class MetadataTransfer<Status extends MetadataRequestStatus, Res
}
} catch (e) {
this.logger.error(e);
// tolerate a known mdapi problem 500/INVALID_CROSS_REFERENCE_KEY: invalid cross reference id
// that happens when request moves out of Pending
if (e instanceof Error && e.name === 'JsonParseError') {
this.logger.debug('Metadata API response not parseable', e);
await Lifecycle.getInstance().emitWarning('Metadata API response not parseable');
return { completed: false };
}
// tolerate intermittent network errors upto retry limit
if (
['ETIMEDOUT', 'ENOTFOUND', 'ECONNRESET', 'socket hang up'].some((retryableNetworkError) =>
Expand Down
12 changes: 12 additions & 0 deletions test/client/metadataTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ describe('MetadataTransfer', () => {
expect(checkStatus.callCount).to.equal(3);
});

it('should tolerate known mdapi error', async () => {
const { checkStatus } = operation.lifecycle;
const networkError1 = new Error('foo');
networkError1.name = 'JsonParseError';
checkStatus.onFirstCall().throws(networkError1);
checkStatus.onSecondCall().throws(networkError1);
checkStatus.onThirdCall().resolves({ done: true });

await operation.pollStatus();
expect(checkStatus.callCount).to.equal(3);
});

it('should throw wrapped error if there are no error listeners', async () => {
const { checkStatus } = operation.lifecycle;
const originalError = new Error('whoops');
Expand Down

0 comments on commit 6e778e6

Please sign in to comment.