mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 02:51:14 +00:00
fix(HTTP Request Node): Cleanup circular references in response (#6590)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
// eslint-disable-next-line max-classes-per-file
|
||||
import { parseString } from 'xml2js';
|
||||
import { removeCircularRefs, isTraversableObject } from './utils';
|
||||
import type { IDataObject, INode, IStatusCodeMessages, JsonObject } from './Interfaces';
|
||||
|
||||
type Severity = 'warning' | 'error';
|
||||
@@ -156,7 +157,7 @@ export abstract class NodeError extends ExecutionBaseError {
|
||||
.map((jsonError) => {
|
||||
if (typeof jsonError === 'string') return jsonError;
|
||||
if (typeof jsonError === 'number') return jsonError.toString();
|
||||
if (this.isTraversableObject(jsonError)) {
|
||||
if (isTraversableObject(jsonError)) {
|
||||
return this.findProperty(jsonError, potentialKeys);
|
||||
}
|
||||
return null;
|
||||
@@ -168,7 +169,7 @@ export abstract class NodeError extends ExecutionBaseError {
|
||||
}
|
||||
return resolvedErrors.join(' | ');
|
||||
}
|
||||
if (this.isTraversableObject(value)) {
|
||||
if (isTraversableObject(value)) {
|
||||
const property = this.findProperty(value, potentialKeys);
|
||||
if (property) {
|
||||
return property;
|
||||
@@ -180,7 +181,7 @@ export abstract class NodeError extends ExecutionBaseError {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key of traversalKeys) {
|
||||
const value = jsonError[key];
|
||||
if (this.isTraversableObject(value)) {
|
||||
if (isTraversableObject(value)) {
|
||||
const property = this.findProperty(value, potentialKeys, traversalKeys);
|
||||
if (property) {
|
||||
return property;
|
||||
@@ -190,47 +191,6 @@ export abstract class NodeError extends ExecutionBaseError {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a value is an object with at least one key, i.e. it can be traversed.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
protected isTraversableObject(value: any): value is JsonObject {
|
||||
return (
|
||||
value &&
|
||||
typeof value === 'object' &&
|
||||
!Array.isArray(value) &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
!!Object.keys(value).length
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove circular references from objects.
|
||||
*/
|
||||
protected removeCircularRefs(obj: JsonObject, seen = new Set()) {
|
||||
seen.add(obj);
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
if (this.isTraversableObject(value)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
seen.has(value)
|
||||
? (obj[key] = { circularReference: true })
|
||||
: this.removeCircularRefs(value, seen);
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((val, index) => {
|
||||
if (seen.has(val)) {
|
||||
value[index] = { circularReference: true };
|
||||
return;
|
||||
}
|
||||
if (this.isTraversableObject(val)) {
|
||||
this.removeCircularRefs(val, seen);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
interface NodeOperationErrorOptions {
|
||||
@@ -317,7 +277,7 @@ export class NodeApiError extends NodeError {
|
||||
|
||||
if (error.error) {
|
||||
// only for request library error
|
||||
this.removeCircularRefs(error.error as JsonObject);
|
||||
removeCircularRefs(error.error as JsonObject);
|
||||
}
|
||||
|
||||
if ((!message && (error.message || (error?.reason as IDataObject)?.message)) || description) {
|
||||
|
||||
Reference in New Issue
Block a user