Skip to content

Commit

Permalink
refactor: global exception handler and user DTO
Browse files Browse the repository at this point in the history
Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>
  • Loading branch information
tipusinghaw committed Oct 5, 2023
1 parent 90d6aed commit ee08aeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
13 changes: 6 additions & 7 deletions apps/api-gateway/common/exception-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ export class CustomExceptionFilter extends BaseExceptionFilter {
if (exception && exception["response"] && exception.message) {

if (Array.isArray(exception["response"].message)) {
exception["response"].message.forEach((msg) => {
errorResponse = {
statusCode: exception["statusCode"] ? exception["statusCode"] : status,
message: msg || 'Internal server error',
error: msg || 'Internal server error'
};
});

errorResponse = {
statusCode: exception["statusCode"] ? exception["statusCode"] : status,
message: exception.message ? exception.message : 'Internal server error',
error: exception["response"].message ? exception["response"].message : exception["response"] ? exception["response"] : 'Internal server error'
};
} else {
errorResponse = {
statusCode: exception["statusCode"] ? exception["statusCode"] : status,
Expand Down
11 changes: 5 additions & 6 deletions apps/api-gateway/src/user/dto/add-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ export class AddUserDetails {
@IsEmail()
@IsNotEmpty({ message: 'Please provide valid email' })
@IsString({ message: 'email should be string' })
@IsOptional()
email?: string;
email: string;

@ApiProperty({ example: 'Alen' })
@IsNotEmpty({ message: 'Please provide valid email' })
@IsString({ message: 'firstName should be string' })
@IsOptional()
firstName?: string;
firstName: string;

@ApiProperty({ example: 'Harvey' })
@IsNotEmpty({ message: 'Please provide valid email' })
@IsString({ message: 'lastName should be string' })
@IsOptional()
lastName?: string;
lastName: string;

@ApiProperty()
@Transform(({ value }) => trim(value))
Expand Down

0 comments on commit ee08aeb

Please sign in to comment.