Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
feat: handle provider already exists error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub-Vacek committed Nov 8, 2023
1 parent 197a8c0 commit 55d8db8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/commands/prepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('prepare CLI command', () => {
{
urlOrSource: fileContent,
name,
options: { quiet: undefined, timeout: 123, force: false },
options: { quiet: undefined, timeout: 123, force: false },
},
{ userError, ux }
);
Expand Down
9 changes: 9 additions & 0 deletions src/common/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type PollResponse =
| {
status: PollStatus.Failed;
failure_reason: string;
context?: string;
result_type: PollResultType;
}
| { status: PollStatus.Cancelled; result_type: PollResultType };
Expand Down Expand Up @@ -123,6 +124,14 @@ export async function pollUrl(

return result.result_url;
} else if (result.status === PollStatus.Failed) {
if (result.context === 'providerAlreadyExists') {
throw userError(
`Failed to ${getJobDescription(result.result_type)}: ${
result.failure_reason
}. Use --force to overwrite existing provider.`,
0
);
}
throw userError(
`Failed to ${getJobDescription(result.result_type)}: ${
result.failure_reason
Expand Down
4 changes: 2 additions & 2 deletions src/logic/prepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('prepareProviderJson', () => {
{
urlOrSource: 'https://superface.ai/path/to/oas.json',
name: providerName,
options: { getDocs: true, timeout: 123, force: false },
options: { getDocs: true, timeout: 123, force: false },
},
{ ux, userError }
)
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('prepareProviderJson', () => {
{
urlOrSource: 'https://superface.ai/path/to/oas.json',
name: providerName,
options: { timeout: 123, force: false },
options: { timeout: 123, force: false },
},
{ ux, userError }
)
Expand Down

0 comments on commit 55d8db8

Please sign in to comment.