Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function ajaxError(adapter, payload, requestData, responseData) {
let error;
if (responseData.errorThrown instanceof Error && payload !== '') {
error = responseData.errorThrown;
} else if (responseData.textStatus === 'timeout') {
error = new TimeoutError();
} else if (responseData.textStatus === 'abort' || responseData.status === 0) {
error = handleAbort(requestData, responseData);
} else {
try {
error = adapter.handleResponse(
responseData.status,
responseData.headers,
payload || responseData.errorThrown,
requestData
);
} catch (e) {
error = e;
}
}
return error;