Skip to content

Commit

Permalink
Only use stack traces from actual Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj committed May 3, 2024
1 parent 236c6a9 commit 21c19cd
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions api/src/middleware/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ErrorCode, isDirectusError } from '@directus/errors';
import type { DeepPartial } from '@directus/types';
import { isObject } from '@directus/utils';
import { getNodeEnv } from '@directus/utils/node';
import type { ErrorRequestHandler, NextFunction, Request, Response } from 'express';
Expand Down Expand Up @@ -32,14 +33,9 @@ export const errorHandler = asyncErrorHandler(async (err, req, res) => {
const receivedErrors: unknown[] = Array.isArray(err) ? err : [err];

for (const error of receivedErrors) {
if (getNodeEnv() === 'development') {
// If available, expose stack trace under error's extensions data
if (isObject(error) && error['stack'] && (error['extensions'] === undefined || isObject(error['extensions']))) {
error['extensions'] = {
...error['extensions'],
stack: error['stack'],
};
}
// In dev mode, if available, expose stack trace under error's extensions data
if (getNodeEnv() === 'development' && error instanceof Error && error.stack) {
((error as DeepPartial<ApiError>).extensions ??= {})['stack'] = error.stack;
}

if (isDirectusError(error)) {
Expand Down

0 comments on commit 21c19cd

Please sign in to comment.