1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

Merge branch 'master' into issue90

This commit is contained in:
Krishna Acondy
2020-09-18 16:38:23 +01:00
committed by GitHub
2 changed files with 45 additions and 14 deletions

View File

@@ -323,17 +323,14 @@ export class SASViyaApiClient {
{
headers
}
).catch((e) => {
console.error(e)
if (e && e.status === 404) {
).catch((err) => {
if (err && err.status === 404) {
throw new Error(
`The context '${contextName}' was not found on this server.`
)
}
throw new Error(
`An error occurred when fetching the context '${contextName}'.`
)
throw err
})
// An If-Match header with the value of the last ETag for the context
@@ -1001,9 +998,19 @@ export class SASViyaApiClient {
if (allJobsInFolder) {
const jobSpec = allJobsInFolder.find((j: Job) => j.name === jobName)
if (!jobSpec) {
throw new Error('Job was not found.')
}
const jobDefinitionLink = jobSpec?.links.find(
(l) => l.rel === 'getResource'
)?.href
if (!jobDefinitionLink) {
throw new Error('Job definition URI was not found.')
}
const requestInfo: any = {
method: 'GET'
}
@@ -1378,12 +1385,8 @@ export class SASViyaApiClient {
const { result: contexts } = await this.request<{ items: Context[] }>(
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
{ headers }
).catch((e) => {
console.error(e)
throw new Error(
`An error occurred when fetching the context '${contextName}'.`
)
).catch((err) => {
throw err
})
if (!contexts || !(contexts.items && contexts.items.length)) {

View File

@@ -37,13 +37,28 @@ export async function makeRequest<T>(
...request,
headers: { ...request.headers, [tokenHeader]: token }
}
return fetch(url, retryRequest).then((res) => {
etag = res.headers.get('ETag')
return responseTransform(res)
})
} else {
let body: any = await response.text()
try {
body = JSON.parse(body)
body.message = `Forbidden. Check your permissions and user groups. ${
body.message || ''
}`
body = JSON.stringify(body)
} catch (_) {}
return Promise.reject({ status: response.status, body })
}
} else {
const body = await response.text()
let body: any = await response.text()
if (needsRetry(body)) {
if (retryCount < retryLimit) {
@@ -65,6 +80,18 @@ export async function makeRequest<T>(
}
}
if (response.status === 401) {
try {
body = JSON.parse(body)
body.message = `Unauthorized request. Check your credentials(client, secret, access token). ${
body.message || ''
}`
body = JSON.stringify(body)
} catch (_) {}
}
return Promise.reject({ status: response.status, body })
}
} else {
@@ -104,5 +131,6 @@ export async function makeRequest<T>(
return responseTransformed
}
})
return { result, etag }
}