From dfb9c28f3a31f5872b2a88985af1c39606a39fd0 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Tue, 29 Dec 2020 10:00:49 +0300 Subject: [PATCH] feat(createComputeContext): added throw an error if context already exists --- src/ContextManager.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ContextManager.ts b/src/ContextManager.ts index fdbfb83..c6b6753 100644 --- a/src/ContextManager.ts +++ b/src/ContextManager.ts @@ -9,8 +9,6 @@ import { SASViyaApiClient } from './SASViyaApiClient' import { prefixMessage } from '@sasjs/utils/error' export class ContextManager { - private sasViyaApiClient: SASViyaApiClient | null = null - constructor( private serverUrl: string, private setCsrfToken: (csrfToken: CsrfToken) => void @@ -74,7 +72,6 @@ export class ContextManager { })) } - // TODO: Check if context already exist, reject with the error if so public async createComputeContext( contextName: string, launchContextName: string, @@ -87,6 +84,14 @@ export class ContextManager { throw new Error('Context name is required.') } + const existingComputeContexts = await this.getComputeContexts(accessToken) + + if ( + existingComputeContexts.find((context) => context.name === contextName) + ) { + throw new Error(`Compute context '${contextName}' already exists.`) + } + if (launchContextName) { const launcherContexts = await this.getLauncherContexts(accessToken)