Skip to content

Commit

Permalink
feat: extract error cause in exception filters
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotsx committed Dec 8, 2024
1 parent c74576e commit 8f880d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/backend/src/common/error/exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class MainExceptionFilter implements ExceptionFilter {
const status = exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;

let message = 'Internal server error';
let cause: unknown;

if (status === HttpStatus.INTERNAL_SERVER_ERROR) {
this.logger.error(`An error occured while calling: ${request.url}`, exception);
Expand All @@ -34,6 +35,7 @@ export class MainExceptionFilter implements ExceptionFilter {
let intlParams: Record<string, string | undefined> | undefined;
if (exception instanceof TranslatableError) {
const response = exception.getResponse();
cause = exception.cause;

if (typeof response === 'string') {
message = response;
Expand All @@ -48,6 +50,7 @@ export class MainExceptionFilter implements ExceptionFilter {
if (status >= 500 && !(exception instanceof TranslatableError)) {
Sentry.captureException(exception, {
tags: {
cause: String(cause),
url: request.url,
status,
},
Expand All @@ -59,6 +62,7 @@ export class MainExceptionFilter implements ExceptionFilter {
message,
path: request.url,
intlParams,
cause,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class AppLifecycleService {

if (!success) {
this.logger.error(`Failed to update app ${appId}: ${message}`);
throw new TranslatableError('APP_ERROR_APP_FAILED_TO_UPDATE', { id: appId });
throw new TranslatableError('APP_ERROR_APP_FAILED_TO_UPDATE', { id: appId }, HttpStatus.INTERNAL_SERVER_ERROR, { cause: message });
}

await this.appRepository.updateApp(appId, {
Expand Down

0 comments on commit 8f880d9

Please sign in to comment.