chore: changed the returned status type for errors in the access-tokens (#4107)

* chore: changed the returned status type for errors in the access-token interceptor

* chore: removed unused pagination args
This commit is contained in:
Balu Babu
2024-06-07 12:08:35 +05:30
committed by GitHub
parent 4bd23a8f4c
commit 465ea2b4e0
4 changed files with 14 additions and 12 deletions

View File

@@ -1,13 +1,14 @@
import {
BadRequestException,
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
UnauthorizedException,
} from '@nestjs/common';
import { Observable, map } from 'rxjs';
import { AccessTokenService } from 'src/access-token/access-token.service';
import * as E from 'fp-ts/Either';
import { ACCESS_TOKEN_NOT_FOUND } from 'src/errors';
@Injectable()
export class AccessTokenInterceptor implements NestInterceptor {
@@ -18,14 +19,15 @@ export class AccessTokenInterceptor implements NestInterceptor {
const authHeader = req.headers.authorization;
const token = authHeader && authHeader.split(' ')[1];
if (!token) {
throw new UnauthorizedException();
throw new BadRequestException(ACCESS_TOKEN_NOT_FOUND);
}
return handler.handle().pipe(
map(async (data) => {
const userAccessToken =
await this.accessTokenService.updateLastUsedForPAT(token);
if (E.isLeft(userAccessToken)) throw new UnauthorizedException();
if (E.isLeft(userAccessToken))
throw new BadRequestException(userAccessToken.left);
return data;
}),