-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bccbf85
commit 8e7516e
Showing
4 changed files
with
25 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 15 additions & 8 deletions
23
apps/users/src/infrastructure/exceptions/exceptions.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
BadRequestException, | ||
ForbiddenException, | ||
HttpException, | ||
Injectable, | ||
InternalServerErrorException, | ||
UnauthorizedException, | ||
ConflictException | ||
} from '@nestjs/common'; | ||
import { IExceptionService, IFormatExceptionMessage, IFormatCommonExceptionMessage } from '../../domain/exceptions/exception-service.interface'; | ||
import { RpcException } from '@nestjs/microservices'; | ||
|
||
@Injectable() | ||
export class ExceptionsService implements IExceptionService { | ||
requestException(data: IFormatCommonExceptionMessage): void { | ||
throw new RpcException({ message: data.message, status: data.code_error }) | ||
throw new HttpException(data.message, data.code_error); | ||
} | ||
badRequestException({ message }: IFormatExceptionMessage): void { | ||
throw new RpcException({ message, status: 400 }) | ||
throw new BadRequestException(message); | ||
} | ||
internalServerErrorException({ message }: IFormatExceptionMessage): void { | ||
throw new RpcException({ message, status: 500 }) | ||
throw new InternalServerErrorException(message); | ||
} | ||
forbiddenException({ message }: IFormatExceptionMessage): void { | ||
throw new RpcException({ message, status: 403 }) | ||
throw new ForbiddenException(message); | ||
} | ||
conflictException({ message }: IFormatExceptionMessage): void { | ||
throw new RpcException({ message, status: 409 }) | ||
throw new ConflictException(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters