diff --git a/api/src/flows.ts b/api/src/flows.ts index f0d96e6ff9..ed4f9d2e1a 100644 --- a/api/src/flows.ts +++ b/api/src/flows.ts @@ -21,7 +21,6 @@ import { getSchema } from './utils/get-schema.js'; import { JobQueue } from './utils/job-queue.js'; import { mapValuesDeep } from './utils/map-values-deep.js'; import { redactObject } from './utils/redact-object.js'; -import { sanitizeError } from './utils/sanitize-error.js'; import { scheduleSynchronizedJob, validateCron } from './utils/schedule.js'; import { isSystemCollection } from '@directus/system-data'; @@ -450,8 +449,9 @@ class FlowManager { let data; if (error instanceof Error) { - // make sure we don't expose the stack trace - data = sanitizeError(error); + // Don't expose the stack trace to the next operation + delete error.stack; + data = error; } else if (typeof error === 'string') { // If the error is a JSON string, parse it and use that as the error data data = isValidJSON(error) ? parseJSON(error) : error; diff --git a/api/src/utils/sanitize-error.test.ts b/api/src/utils/sanitize-error.test.ts deleted file mode 100644 index f48f02fc36..0000000000 --- a/api/src/utils/sanitize-error.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { createError } from '@directus/errors'; -import { describe, expect, test } from 'vitest'; -import { sanitizeError } from './sanitize-error.js'; - -describe('sanitizeError', () => { - test('removes stack trace from Error', () => { - const error = new Error('test message', { - cause: 'test', - }); - - const result = sanitizeError(error); - - expect(result.stack).toBe(undefined); - expect(result.message).toBe(error.message); - expect(result.cause).toBe(error.cause); - }); - - test('removes stack trace from DirectusError', () => { - const DummyError = createError<{ more: string }>('TEAPOT', 'test message', 418); - const error = new DummyError({ more: 'info' }); - - const result = sanitizeError(error); - - expect(result.stack).toBe(undefined); - expect(result.message).toBe(error.message); - expect(result.code).toBe(error.code); - expect(result.status).toBe(error.status); - expect(result.extensions).toStrictEqual(result.extensions); - }); -}); diff --git a/api/src/utils/sanitize-error.ts b/api/src/utils/sanitize-error.ts deleted file mode 100644 index a25db5dff0..0000000000 --- a/api/src/utils/sanitize-error.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function sanitizeError(error: T): T { - // clear the stack - if (error.stack !== undefined) { - delete error.stack; - } - - return error; -}