Skip to content

Commit

Permalink
fix: handle errors from /share-results
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilianna Papastefanou committed Jul 12, 2022
1 parent e3fc9b9 commit 5871079
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export async function shareResults({
},
});

switch (res.statusCode) {
case 401:
throw AuthFailedError();
case 422:
throw new ValidationError(
res.body.error ?? 'An error occurred, please contact Snyk support',
);
case 429:
throw new TestLimitReachedError();
if (res.statusCode === 401) {
throw AuthFailedError();
} else if (res.statusCode === 429) {
throw new TestLimitReachedError();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
} else if (res.statusCode! < 200 || res.statusCode! > 299) {
throw new ValidationError(
res.body.error ?? 'An error occurred, please contact Snyk support',
);
}

return { projectPublicIds: body, gitRemoteUrl: gitTarget?.remoteUrl };
Expand Down
4 changes: 4 additions & 0 deletions test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
res.status(200).send({});
});

app.post(basePath + '/iac-cli-share-results', (req, res) => {
res.status(200).send({});
});

app.post(basePath + '/analytics/cli', (req, res) => {
res.status(200).send({});
});
Expand Down

0 comments on commit 5871079

Please sign in to comment.