Skip to content

Commit

Permalink
Merge pull request #64 from mapeveri/refactor/fix-refresh-controller
Browse files Browse the repository at this point in the history
Refactor: Improvements error controller
  • Loading branch information
mapeveri authored Nov 30, 2023
2 parents 64ff247 + e3afde6 commit b19c7ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request } from 'express';
import FindUserQuery from '@src/languages/application/user/query/find/findUserQuery';
import { Controller, Get, HttpCode, Inject, Req, UseGuards } from '@nestjs/common';
import { Controller, Get, HttpCode, HttpException, HttpStatus, Inject, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/JwtAuthGuard';
import MeGetResponseDto from './meGetResponseDto';
import {
Expand All @@ -27,7 +27,7 @@ export default class MeGetController {
async run(@Req() request: Request): Promise<MeGetResponseDto> {
const userId = request.user?.id;
if (!userId) {
throw new Error('Invalid user');
throw new HttpException('Invalid user', HttpStatus.FORBIDDEN);
}

const data = await this.queryBus.ask(new FindUserQuery(userId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, HttpCode, Inject, Post } from '@nestjs/common';
import { Body, Controller, HttpCode, HttpException, HttpStatus, Inject, Post } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import LoginPostResponseDto from './loginPostResponseDto';
import { ApiBadRequestResponse, ApiInternalServerErrorResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger';
Expand All @@ -20,7 +20,7 @@ export default class RefreshTokenPostController {
async run(@Body() payload: RefreshTokenPostDto): Promise<RefreshTokenPostResponseDto> {
const decodedRefreshToken = this.jwtService.verify(payload.refreshToken);
if (decodedRefreshToken.revoked) {
throw new Error('Token revoked');
throw new HttpException('Token revocado', HttpStatus.FORBIDDEN);
}

const user = await this.queryBus.ask(new FindUserQuery(decodedRefreshToken.id));
Expand Down

0 comments on commit b19c7ba

Please sign in to comment.