add httpExceptionHandlerService to oauthfilter (#9518)
## Context 500 from oauth controllers are never captured, fixing this
This commit is contained in:
@ -11,7 +11,10 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Repository } from 'typeorm';
|
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 { 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 { 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';
|
import { GoogleOauthGuard } from 'src/engine/core-modules/auth/guards/google-oauth.guard';
|
||||||
@ -121,7 +124,7 @@ export class GoogleAuthController {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw err;
|
throw new AuthException(AuthExceptionCode.INTERNAL_SERVER_ERROR, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,4 @@
|
|||||||
import {
|
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
|
||||||
ArgumentsHost,
|
|
||||||
Catch,
|
|
||||||
ExceptionFilter,
|
|
||||||
InternalServerErrorException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
|
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
|
|
||||||
@ -12,10 +7,14 @@ import {
|
|||||||
AuthExceptionCode,
|
AuthExceptionCode,
|
||||||
} from 'src/engine/core-modules/auth/auth.exception';
|
} from 'src/engine/core-modules/auth/auth.exception';
|
||||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/service/domain-manager.service';
|
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)
|
@Catch(AuthException)
|
||||||
export class AuthOAuthExceptionFilter implements ExceptionFilter {
|
export class AuthOAuthExceptionFilter implements ExceptionFilter {
|
||||||
constructor(private readonly domainManagerService: DomainManagerService) {}
|
constructor(
|
||||||
|
private readonly domainManagerService: DomainManagerService,
|
||||||
|
private readonly httpExceptionHandlerService: HttpExceptionHandlerService,
|
||||||
|
) {}
|
||||||
|
|
||||||
catch(exception: AuthException, host: ArgumentsHost) {
|
catch(exception: AuthException, host: ArgumentsHost) {
|
||||||
const ctx = host.switchToHttp();
|
const ctx = host.switchToHttp();
|
||||||
@ -28,7 +27,11 @@ export class AuthOAuthExceptionFilter implements ExceptionFilter {
|
|||||||
.redirect(this.domainManagerService.getBaseUrl().toString());
|
.redirect(this.domainManagerService.getBaseUrl().toString());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InternalServerErrorException(exception.message);
|
return this.httpExceptionHandlerService.handleError(
|
||||||
|
exception,
|
||||||
|
response,
|
||||||
|
500,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user