Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ jobs:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --all-projects --fail-on=all
json: true
continue-on-error: true
- uses: contentstack/sca-policy@main
28 changes: 22 additions & 6 deletions src/core/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import fetch from 'runtime/http.js';

// JS SDK version
const version = '{{VERSION}}';
let environment,
api_key;
export default function Request (stack, fetchOptions) {
const requestParams = stack.requestParams;
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -112,6 +110,14 @@ function fetchRetry (stack, queryParams, fetchOptions, resolve, reject, retryDel
for (let index = 0; index < plugins.length && typeof plugins[index].onResponse === 'function'; index++) { json = plugins[index].onResponse(stack, request, response, json); }

resolve(json);
}).catch((err) => {
if (fetchOptions.debug) fetchOptions.logHandler('error', err);
const isSocketOrAbort = (err && (err.message === 'terminated' || (err.cause && (err.cause.code === 'UND_ERR_SOCKET' || err.cause.code === 'UND_ERR_ABORTED'))));
if (isSocketOrAbort && retryLimit > 0) {
onError(err);
} else {
reject(err);
}
});
} else {
const { status, statusText } = response;
Expand All @@ -124,13 +130,23 @@ function fetchRetry (stack, queryParams, fetchOptions, resolve, reject, retryDel
if (fetchOptions.debug) fetchOptions.logHandler('error', errorDetails);
reject(errorDetails);
}
}).catch(() => {
if (fetchOptions.debug) fetchOptions.logHandler('error', { status, statusText });
reject({ status, statusText });
}).catch((err) => {
if (fetchOptions.debug) fetchOptions.logHandler('error', err);
const isSocketOrAbort = (err && (err.message === 'terminated' || (err.cause && (err.cause.code === 'UND_ERR_SOCKET' || err.cause.code === 'UND_ERR_ABORTED'))));
if (isSocketOrAbort && retryLimit > 0) {
onError(err);
} else {
reject(err || { status, statusText });
}
});
}
}).catch((error) => {
if (fetchOptions.debug) fetchOptions.logHandler('error', error);
reject(error);
const isSocketOrAbort = (error && (error.message === 'terminated' || (error.cause && (error.cause.code === 'UND_ERR_SOCKET' || error.cause.code === 'UND_ERR_ABORTED'))));
if (isSocketOrAbort && retryLimit > 0) {
onError(error);
} else {
reject(error);
}
});
}
Loading