chore: handle conferencing callback missing state error (#20081)

This commit is contained in:
Morgan
2025-03-14 15:49:04 +02:00
committed by GitHub
parent 543d4bb6b3
commit 580b03f2b9
@@ -35,6 +35,7 @@ import {
Redirect,
UnauthorizedException,
Req,
HttpException,
} from "@nestjs/common";
import { ApiOperation, ApiTags as DocsTags } from "@nestjs/swagger";
import { plainToInstance } from "class-transformer";
@@ -56,7 +57,7 @@ export type OAuthCallbackState = {
})
@DocsTags("Conferencing")
export class ConferencingController {
private readonly logger = new Logger("Platform Gcal Provider");
private readonly logger = new Logger("ConferencingController");
constructor(
private readonly tokensRepository: TokensRepository,
@@ -144,6 +145,10 @@ export class ConferencingController {
@Query("error") error: string | undefined,
@Query("error_description") error_description: string | undefined
): Promise<{ url: string }> {
if (!state) {
throw new BadRequestException("Missing `state` query param");
}
const decodedCallbackState: OAuthCallbackState = JSON.parse(state);
try {
const userId = await this.tokensRepository.getAccessTokenOwnerId(decodedCallbackState.accessToken);
@@ -169,6 +174,9 @@ export class ConferencingController {
);
}
} catch (error) {
if (error instanceof HttpException || error instanceof Error) {
this.logger.error(error.message);
}
return {
url: decodedCallbackState.onErrorReturnTo ?? "",
};