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 ffb7eea
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
Expand Up @@ -5,6 +5,7 @@ import type { ErrorRequestHandler, NextFunction, Request, Response } from 'expre
import getDatabase from '../database/index.js';
import emitter from '../emitter.js';
import { useLogger } from '../logger.js';
import type { DeepPartial } from '@directus/types';

type ApiError = {
message: string;
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 ffb7eea

Please sign in to comment.