mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix: Error processing and output pane improvements (no-changelog) (#9626)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { isTraversableObject } from '../../utils';
|
||||
import { isTraversableObject, jsonParse } from '../../utils';
|
||||
import type { IDataObject, INode, JsonObject } from '@/Interfaces';
|
||||
import { ExecutionBaseError } from './execution-base.error';
|
||||
|
||||
@@ -81,9 +81,16 @@ export abstract class NodeError extends ExecutionBaseError {
|
||||
traversalKeys: string[] = [],
|
||||
): string | null {
|
||||
for (const key of potentialKeys) {
|
||||
const value = jsonError[key];
|
||||
let value = jsonError[key];
|
||||
if (value) {
|
||||
if (typeof value === 'string') return value;
|
||||
if (typeof value === 'string') {
|
||||
try {
|
||||
value = jsonParse(value);
|
||||
} catch (error) {
|
||||
return value as string;
|
||||
}
|
||||
if (typeof value === 'string') return value;
|
||||
}
|
||||
if (typeof value === 'number') return value.toString();
|
||||
if (Array.isArray(value)) {
|
||||
const resolvedErrors: string[] = value
|
||||
|
||||
@@ -39,8 +39,9 @@ interface NodeApiErrorOptions extends NodeOperationErrorOptions {
|
||||
|
||||
/**
|
||||
* Top-level properties where an error message can be found in an API response.
|
||||
* order is important, precedence is from top to bottom
|
||||
*/
|
||||
const ERROR_MESSAGE_PROPERTIES = [
|
||||
const POSSIBLE_ERROR_MESSAGE_KEYS = [
|
||||
'cause',
|
||||
'error',
|
||||
'message',
|
||||
@@ -60,6 +61,7 @@ const ERROR_MESSAGE_PROPERTIES = [
|
||||
'errorDescription',
|
||||
'error_description',
|
||||
'error_summary',
|
||||
'error_info',
|
||||
'title',
|
||||
'text',
|
||||
'field',
|
||||
@@ -67,10 +69,15 @@ const ERROR_MESSAGE_PROPERTIES = [
|
||||
'type',
|
||||
];
|
||||
|
||||
/**
|
||||
* Properties where a nested object can be found in an API response.
|
||||
*/
|
||||
const POSSIBLE_NESTED_ERROR_OBJECT_KEYS = ['Error', 'error', 'err', 'response', 'body', 'data'];
|
||||
|
||||
/**
|
||||
* Top-level properties where an HTTP error code can be found in an API response.
|
||||
*/
|
||||
const ERROR_STATUS_PROPERTIES = [
|
||||
const POSSIBLE_ERROR_STATUS_KEYS = [
|
||||
'statusCode',
|
||||
'status',
|
||||
'code',
|
||||
@@ -79,11 +86,6 @@ const ERROR_STATUS_PROPERTIES = [
|
||||
'error_code',
|
||||
];
|
||||
|
||||
/**
|
||||
* Properties where a nested object can be found in an API response.
|
||||
*/
|
||||
const ERROR_NESTING_PROPERTIES = ['error', 'err', 'response', 'body', 'data'];
|
||||
|
||||
/**
|
||||
* Descriptive messages for common HTTP status codes
|
||||
* this is used by NodeApiError class
|
||||
@@ -187,7 +189,11 @@ export class NodeApiError extends NodeError {
|
||||
this.httpCode = errorResponse.httpCode as string;
|
||||
} else {
|
||||
this.httpCode =
|
||||
this.findProperty(errorResponse, ERROR_STATUS_PROPERTIES, ERROR_NESTING_PROPERTIES) ?? null;
|
||||
this.findProperty(
|
||||
errorResponse,
|
||||
POSSIBLE_ERROR_STATUS_KEYS,
|
||||
POSSIBLE_NESTED_ERROR_OBJECT_KEYS,
|
||||
) ?? null;
|
||||
}
|
||||
|
||||
this.level = level ?? 'warning';
|
||||
@@ -222,8 +228,8 @@ export class NodeApiError extends NodeError {
|
||||
} else {
|
||||
this.description = this.findProperty(
|
||||
errorResponse,
|
||||
ERROR_MESSAGE_PROPERTIES,
|
||||
ERROR_NESTING_PROPERTIES,
|
||||
POSSIBLE_ERROR_MESSAGE_KEYS,
|
||||
POSSIBLE_NESTED_ERROR_OBJECT_KEYS,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -266,8 +272,8 @@ export class NodeApiError extends NodeError {
|
||||
const topLevelKey = Object.keys(result)[0];
|
||||
this.description = this.findProperty(
|
||||
result[topLevelKey],
|
||||
ERROR_MESSAGE_PROPERTIES,
|
||||
['Error'].concat(ERROR_NESTING_PROPERTIES),
|
||||
POSSIBLE_ERROR_MESSAGE_KEYS,
|
||||
POSSIBLE_NESTED_ERROR_OBJECT_KEYS,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user