mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Remove over-engineered sanitizeError function (#21750)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
export function sanitizeError<T extends Error>(error: T): T {
|
||||
// clear the stack
|
||||
if (error.stack !== undefined) {
|
||||
delete error.stack;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
Reference in New Issue
Block a user