mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(editor): Improve errors in output panel (#8644)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -15,7 +15,12 @@ import { NodeError } from './abstract/node.error';
|
||||
import { removeCircularRefs } from '../utils';
|
||||
import type { ReportingOptions } from './application.error';
|
||||
import { AxiosError } from 'axios';
|
||||
import { NO_OP_NODE_TYPE } from '../Constants';
|
||||
import {
|
||||
NO_OP_NODE_TYPE,
|
||||
UNKNOWN_ERROR_DESCRIPTION,
|
||||
UNKNOWN_ERROR_MESSAGE,
|
||||
UNKNOWN_ERROR_MESSAGE_CRED,
|
||||
} from '../Constants';
|
||||
|
||||
export interface NodeOperationErrorOptions {
|
||||
message?: string;
|
||||
@@ -103,9 +108,6 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = {
|
||||
'504': 'Gateway timed out - perhaps try again later?',
|
||||
};
|
||||
|
||||
const UNKNOWN_ERROR_MESSAGE = 'UNKNOWN ERROR - check the detailed error for more information';
|
||||
const UNKNOWN_ERROR_MESSAGE_CRED = 'UNKNOWN ERROR';
|
||||
|
||||
/**
|
||||
* Class for instantiating an error in an API response, e.g. a 404 Not Found response,
|
||||
* with an HTTP error code, an error message and a description.
|
||||
@@ -130,6 +132,8 @@ export class NodeApiError extends NodeError {
|
||||
) {
|
||||
super(node, errorResponse);
|
||||
|
||||
this.addToMessages(errorResponse.message as string);
|
||||
|
||||
if (!httpCode && errorResponse instanceof AxiosError) {
|
||||
httpCode = errorResponse.response?.status?.toString();
|
||||
}
|
||||
@@ -176,6 +180,8 @@ export class NodeApiError extends NodeError {
|
||||
// set http code of this error
|
||||
if (httpCode) {
|
||||
this.httpCode = httpCode;
|
||||
} else if (errorResponse.httpCode) {
|
||||
this.httpCode = errorResponse.httpCode as string;
|
||||
} else {
|
||||
this.httpCode =
|
||||
this.findProperty(errorResponse, ERROR_STATUS_PROPERTIES, ERROR_NESTING_PROPERTIES) ?? null;
|
||||
@@ -187,6 +193,25 @@ export class NodeApiError extends NodeError {
|
||||
this.level = 'warning';
|
||||
}
|
||||
|
||||
if (
|
||||
errorResponse?.response &&
|
||||
typeof errorResponse?.response === 'object' &&
|
||||
!Array.isArray(errorResponse.response) &&
|
||||
errorResponse.response.data &&
|
||||
typeof errorResponse.response.data === 'object' &&
|
||||
!Array.isArray(errorResponse.response.data)
|
||||
) {
|
||||
const data = errorResponse.response.data;
|
||||
|
||||
if (data.message) {
|
||||
description = data.message as string;
|
||||
} else if (data.error && ((data.error as IDataObject) || {}).message) {
|
||||
description = (data.error as IDataObject).message as string;
|
||||
}
|
||||
|
||||
this.context.data = data;
|
||||
}
|
||||
|
||||
// set description of this error
|
||||
if (description) {
|
||||
this.description = description;
|
||||
@@ -204,7 +229,9 @@ export class NodeApiError extends NodeError {
|
||||
}
|
||||
}
|
||||
|
||||
// set message if provided or set default message based on http code
|
||||
// set message if provided
|
||||
// set default message based on http code
|
||||
// or use raw error message
|
||||
if (message) {
|
||||
this.message = message;
|
||||
} else {
|
||||
@@ -217,9 +244,9 @@ export class NodeApiError extends NodeError {
|
||||
}
|
||||
|
||||
// if message contain common error code set descriptive message and update description
|
||||
[this.message, this.description] = this.setDescriptiveErrorMessage(
|
||||
[this.message, this.messages] = this.setDescriptiveErrorMessage(
|
||||
this.message,
|
||||
this.description,
|
||||
this.messages,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
this.httpCode ||
|
||||
(errorResponse?.code as string) ||
|
||||
@@ -259,29 +286,44 @@ export class NodeApiError extends NodeError {
|
||||
|
||||
if (!this.httpCode) {
|
||||
this.httpCode = null;
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
this.message = this.message || this.description || UNKNOWN_ERROR_MESSAGE;
|
||||
|
||||
if (!this.message) {
|
||||
if (this.description) {
|
||||
this.message = this.description;
|
||||
this.description = undefined;
|
||||
} else {
|
||||
this.message = UNKNOWN_ERROR_MESSAGE;
|
||||
this.description = UNKNOWN_ERROR_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (STATUS_CODE_MESSAGES[this.httpCode]) {
|
||||
this.description = this.updateDescription(this.message, this.description);
|
||||
this.addToMessages(this.message);
|
||||
this.message = STATUS_CODE_MESSAGES[this.httpCode];
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this.httpCode.charAt(0)) {
|
||||
case '4':
|
||||
this.description = this.updateDescription(this.message, this.description);
|
||||
this.addToMessages(this.message);
|
||||
this.message = STATUS_CODE_MESSAGES['4XX'];
|
||||
break;
|
||||
case '5':
|
||||
this.description = this.updateDescription(this.message, this.description);
|
||||
this.addToMessages(this.message);
|
||||
this.message = STATUS_CODE_MESSAGES['5XX'];
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
this.message = this.message || this.description || UNKNOWN_ERROR_MESSAGE;
|
||||
if (!this.message) {
|
||||
if (this.description) {
|
||||
this.message = this.description;
|
||||
this.description = undefined;
|
||||
} else {
|
||||
this.message = UNKNOWN_ERROR_MESSAGE;
|
||||
this.description = UNKNOWN_ERROR_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.node.type === NO_OP_NODE_TYPE && this.message === UNKNOWN_ERROR_MESSAGE) {
|
||||
this.message = `${UNKNOWN_ERROR_MESSAGE_CRED} - ${this.httpCode}`;
|
||||
|
||||
Reference in New Issue
Block a user