From 55d8db80abac603ef3c2d8ea231449de2ee6263e Mon Sep 17 00:00:00 2001 From: Jakub Vacek Date: Wed, 8 Nov 2023 08:03:31 +0100 Subject: [PATCH] feat: handle provider already exists error --- src/commands/prepare.test.ts | 2 +- src/common/polling.ts | 9 +++++++++ src/logic/prepare.test.ts | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/commands/prepare.test.ts b/src/commands/prepare.test.ts index 84e4ab83..5d8c3449 100644 --- a/src/commands/prepare.test.ts +++ b/src/commands/prepare.test.ts @@ -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 } ); diff --git a/src/common/polling.ts b/src/common/polling.ts index 398ed1ef..03022ddd 100644 --- a/src/common/polling.ts +++ b/src/common/polling.ts @@ -37,6 +37,7 @@ type PollResponse = | { status: PollStatus.Failed; failure_reason: string; + context?: string; result_type: PollResultType; } | { status: PollStatus.Cancelled; result_type: PollResultType }; @@ -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 diff --git a/src/logic/prepare.test.ts b/src/logic/prepare.test.ts index 17112167..b2ce9357 100644 --- a/src/logic/prepare.test.ts +++ b/src/logic/prepare.test.ts @@ -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 } ) @@ -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 } )