Skip to content

Commit

Permalink
add httpExceptionHandlerService to oauthfilter (#9518)
Browse files Browse the repository at this point in the history
## Context
500 from oauth controllers are never captured, fixing this
  • Loading branch information
Weiko authored Jan 9, 2025
1 parent acc3aa6 commit 524962a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Response } from 'express';
import { Repository } from 'typeorm';

import { AuthException } from 'src/engine/core-modules/auth/auth.exception';
import {
AuthException,
AuthExceptionCode,
} from 'src/engine/core-modules/auth/auth.exception';
import { AuthOAuthExceptionFilter } from 'src/engine/core-modules/auth/filters/auth-oauth-exception.filter';
import { AuthRestApiExceptionFilter } from 'src/engine/core-modules/auth/filters/auth-rest-api-exception.filter';
import { GoogleOauthGuard } from 'src/engine/core-modules/auth/guards/google-oauth.guard';
Expand Down Expand Up @@ -121,7 +124,7 @@ export class GoogleAuthController {
}),
);
}
throw err;
throw new AuthException(AuthExceptionCode.INTERNAL_SERVER_ERROR, err);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
ArgumentsHost,
Catch,
ExceptionFilter,
InternalServerErrorException,
} from '@nestjs/common';
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';

import { Response } from 'express';

Expand All @@ -12,10 +7,14 @@ import {
AuthExceptionCode,
} from 'src/engine/core-modules/auth/auth.exception';
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/service/domain-manager.service';
import { HttpExceptionHandlerService } from 'src/engine/core-modules/exception-handler/http-exception-handler.service';

@Catch(AuthException)
export class AuthOAuthExceptionFilter implements ExceptionFilter {
constructor(private readonly domainManagerService: DomainManagerService) {}
constructor(
private readonly domainManagerService: DomainManagerService,
private readonly httpExceptionHandlerService: HttpExceptionHandlerService,
) {}

catch(exception: AuthException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
Expand All @@ -28,7 +27,11 @@ export class AuthOAuthExceptionFilter implements ExceptionFilter {
.redirect(this.domainManagerService.getBaseUrl().toString());
break;
default:
throw new InternalServerErrorException(exception.message);
return this.httpExceptionHandlerService.handleError(
exception,
response,
500,
);
}
}
}

0 comments on commit 524962a

Please sign in to comment.