fix(core): Deduplicate error handling in nodes (#4319)

* Fix issue with isAxios property

* 🥅 Deduplicate errors handeling improve errors for credentials

* 🎨 correctly throws error
This commit is contained in:
agobrech
2022-11-11 11:32:43 +01:00
committed by GitHub
parent d35d63a855
commit c7133ecd3f
35 changed files with 50 additions and 187 deletions

View File

@@ -255,9 +255,12 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = {
'502': 'Bad gateway - the service failed to handle your request',
'503': 'Service unavailable - perhaps try again later?',
'504': 'Gateway timed out - perhaps try again later?',
ECONNREFUSED: 'The service refused the connection - perhaps it is offline',
};
const UNKNOWN_ERROR_MESSAGE = 'UNKNOWN ERROR - check the detailed error for more information';
const UNKNOWN_ERROR_MESSAGE_CRED = 'UNKNOWN ERROR';
interface NodeApiErrorOptions extends NodeOperationErrorOptions {
message?: string;
@@ -282,10 +285,14 @@ export class NodeApiError extends NodeError {
// only for request library error
this.removeCircularRefs(error.error as JsonObject);
}
// if it's an error generated by axios
// look for descriptions in the response object
if (error.isAxiosError && error.response) {
error = error.response as JsonObject;
if (error.reason) {
const reason: IDataObject = error.reason as unknown as IDataObject;
if (reason.isAxiosError && reason.response) {
error = reason.response as JsonObject;
}
}
if (message) {
@@ -351,5 +358,8 @@ export class NodeApiError extends NodeError {
default:
this.message = UNKNOWN_ERROR_MESSAGE;
}
if (this.node.type === 'n8n-nodes-base.noOp' && this.message === UNKNOWN_ERROR_MESSAGE) {
this.message = `${UNKNOWN_ERROR_MESSAGE_CRED} - ${this.httpCode}`;
}
}
}