Skip to content

Commit

Permalink
Merge pull request #14 from toufiq-austcse/feature/error-handling
Browse files Browse the repository at this point in the history
feature: validation error
  • Loading branch information
toufiq-austcse authored May 6, 2023
2 parents d90aa02 + a75976c commit ea4cb9a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AuthService {
if (currentUser) {
throw new BadRequestException(JSON.stringify({
key: 'email',
message: 'email already exists'
message: 'email already registered'
}));
}
let newUserObj = await this.createUserObjFromSignUpReqDto(dto);
Expand Down
2 changes: 1 addition & 1 deletion src/api/deployments/services/deployment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class DeploymentService {
if (!deploymentType) {
throw new BadRequestException({
key: 'deployment_type_id',
message: 'Invalid deployment type id'
message: 'Invalid deployment type'
});
}
if (deploymentType.status === DEPLOYMENT_TYPE_STATUS.DISABLED) {
Expand Down
10 changes: 9 additions & 1 deletion src/common/dto/base-api-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export function SwaggerBaseApiResponse<T>(type: T, statusCode: number): typeof B

@ApiProperty({ default: statusCode })
public declare status: number;

@ApiProperty({ default: [] })
public declare errors: string[];
}

// NOTE : Overwrite the returned class name, otherwise whichever type calls this function in the last,
Expand Down Expand Up @@ -57,18 +60,23 @@ export class BaseApiErrorObject {

export class BaseApiErrorResponse {
public status: number;
public declare errors: string[];

@ApiProperty()
public message: string;


@ApiProperty({ default: null })
public data: any;
}

export function SwaggerBaseApiErrorResponse(statusCode: number): typeof BaseApiErrorResponse {
export function SwaggerBaseApiErrorResponse(statusCode: number, errors: string[]=[]): typeof BaseApiErrorResponse {
class ExtendedBaseApiErrorResponse extends BaseApiErrorResponse {
@ApiProperty({ default: statusCode })
public declare status: number;

@ApiProperty({ default: errors })
public declare errors: string[];
}

// NOTE : Overwrite the returned class name, otherwise whichever type calls this function in the last,
Expand Down
3 changes: 2 additions & 1 deletion src/common/interceptors/response.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class ResponseInterceptor implements NestInterceptor {
return {
status: statusCode,
message: res.message,
data: res.data,
errors: [],
data: res.data
};
})
);
Expand Down

0 comments on commit ea4cb9a

Please sign in to comment.