mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
Revert "fix(core): Improve axios error handling in nodes (#5699)"
This reverts commit 33d9784319.
This commit is contained in:
@@ -75,7 +75,6 @@ import {
|
||||
ExpressionError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import pick from 'lodash.pick';
|
||||
import { Agent } from 'https';
|
||||
import { stringify } from 'qs';
|
||||
import type { Token } from 'oauth-1.0a';
|
||||
@@ -676,47 +675,50 @@ async function proxyRequestToAxios(
|
||||
return body;
|
||||
}
|
||||
} catch (error) {
|
||||
const { config, response } = error;
|
||||
const { request, response, isAxiosError, toJSON, config, ...errorData } = error;
|
||||
if (configObject.simple === false && response) {
|
||||
if (configObject.resolveWithFullResponse) {
|
||||
return {
|
||||
body: response.data,
|
||||
headers: response.headers,
|
||||
statusCode: response.status,
|
||||
statusMessage: response.statusText,
|
||||
};
|
||||
} else {
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
// Axios hydrates the original error with more data. We extract them.
|
||||
// https://github.com/axios/axios/blob/master/lib/core/enhanceError.js
|
||||
// Note: `code` is ignored as it's an expected part of the errorData.
|
||||
if (error.isAxiosError) {
|
||||
if (response) {
|
||||
Logger.debug('Request proxied to Axios failed', { status: response.status });
|
||||
let responseData = response.data;
|
||||
if (response) {
|
||||
Logger.debug('Request proxied to Axios failed', { status: response.status });
|
||||
let responseData = response.data;
|
||||
|
||||
if (Buffer.isBuffer(responseData) || responseData instanceof Readable) {
|
||||
responseData = await binaryToBuffer(responseData).then((buffer) =>
|
||||
buffer.toString('utf-8'),
|
||||
);
|
||||
}
|
||||
|
||||
if (configObject.simple === false) {
|
||||
if (configObject.resolveWithFullResponse) {
|
||||
return {
|
||||
body: responseData,
|
||||
headers: response.headers,
|
||||
statusCode: response.status,
|
||||
statusMessage: response.statusText,
|
||||
};
|
||||
} else {
|
||||
return responseData;
|
||||
}
|
||||
}
|
||||
|
||||
const message = `${response.status as number} - ${JSON.stringify(responseData)}`;
|
||||
throw Object.assign(new Error(message, { cause: error }), {
|
||||
status: response.status,
|
||||
options: pick(config ?? {}, ['url', 'method', 'data', 'headers']),
|
||||
});
|
||||
} else {
|
||||
throw Object.assign(new Error(error.message, { cause: error }), {
|
||||
options: pick(config ?? {}, ['url', 'method', 'data', 'headers']),
|
||||
});
|
||||
if (Buffer.isBuffer(responseData) || responseData instanceof Readable) {
|
||||
responseData = await binaryToBuffer(responseData).then((buffer) =>
|
||||
buffer.toString('utf-8'),
|
||||
);
|
||||
}
|
||||
error.message = `${response.status as number} - ${JSON.stringify(responseData)}`;
|
||||
}
|
||||
|
||||
error.cause = errorData;
|
||||
error.error = error.response?.data || errorData;
|
||||
error.statusCode = error.response?.status;
|
||||
error.options = config || {};
|
||||
|
||||
// Remove not needed data and so also remove circular references
|
||||
error.request = undefined;
|
||||
error.config = undefined;
|
||||
error.options.adapter = undefined;
|
||||
error.options.httpsAgent = undefined;
|
||||
error.options.paramsSerializer = undefined;
|
||||
error.options.transformRequest = undefined;
|
||||
error.options.transformResponse = undefined;
|
||||
error.options.validateStatus = undefined;
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user