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:
@@ -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;
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user