From afec5609521a62c3ac0d45a35599831aa1874fb3 Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Mon, 14 Sep 2020 16:26:27 +0200 Subject: [PATCH] fix: JES API error handling if job does not exist --- src/SASViyaApiClient.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index b05e207..e9d4cf4 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -1001,9 +1001,21 @@ export class SASViyaApiClient { if (allJobsInFolder) { const jobSpec = allJobsInFolder.find((j: Job) => j.name === jobName) + + if (!jobSpec) { + console.error('Job was not found.') + throw new Error('Job was not found.') + } + const jobDefinitionLink = jobSpec?.links.find( (l) => l.rel === 'getResource' )?.href + + if (!jobDefinitionLink) { + console.error('Job definition URI was not found.') + throw new Error('Job definition URI was not found.') + } + const requestInfo: any = { method: 'GET' }