Skip to content

Commit

Permalink
fix: add logger for errors, return correct error when resume is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed Nov 22, 2023
1 parent 27758c7 commit 4baecb2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apps/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ForbiddenException,
Injectable,
InternalServerErrorException,
Logger,
} from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt";
Expand Down Expand Up @@ -115,6 +116,7 @@ export class AuthService {
throw new BadRequestException(ErrorMessage.UserAlreadyExists);
}

Logger.error(error);
throw new InternalServerErrorException(error);
}
}
Expand Down Expand Up @@ -213,6 +215,7 @@ export class AuthService {

await this.mailService.sendEmail({ to: email, subject, text });
} catch (error) {
Logger.error(error);
throw new InternalServerErrorException(error);
}
}
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/resume/resume.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class ResumeController {
throw new BadRequestException(ErrorMessage.ResumeSlugAlreadyExists);
}

Logger.error(error);
throw new InternalServerErrorException(error);
}
}
Expand All @@ -69,6 +70,7 @@ export class ResumeController {
throw new BadRequestException(ErrorMessage.ResumeSlugAlreadyExists);
}

Logger.error(error);
throw new InternalServerErrorException(error);
}
}
Expand Down
19 changes: 16 additions & 3 deletions apps/server/src/resume/resume.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BadRequestException, Injectable } from "@nestjs/common";
import {
BadRequestException,
Injectable,
InternalServerErrorException,
Logger,
} from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { CreateResumeDto, ImportResumeDto, ResumeDto, UpdateResumeDto } from "@reactive-resume/dto";
import { defaultResumeData, ResumeData } from "@reactive-resume/schema";
Expand Down Expand Up @@ -127,14 +132,21 @@ export class ResumeService {

async update(userId: string, id: string, updateResumeDto: UpdateResumeDto) {
try {
const { locked } = await this.prisma.resume.findUniqueOrThrow({
where: { id },
select: { locked: true },
});

if (locked) throw new BadRequestException(ErrorMessage.ResumeLocked);

const resume = await this.prisma.resume.update({
data: {
title: updateResumeDto.title,
slug: updateResumeDto.slug,
visibility: updateResumeDto.visibility,
data: updateResumeDto.data as unknown as Prisma.JsonObject,
},
where: { userId_id: { userId, id }, locked: false },
where: { userId_id: { userId, id } },
});

await Promise.all([
Expand All @@ -147,7 +159,8 @@ export class ResumeService {
return resume;
} catch (error) {
if (error.code === "P2025") {
throw new BadRequestException(ErrorMessage.ResumeLocked);
Logger.error(error);
throw new InternalServerErrorException(error);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Delete,
Get,
InternalServerErrorException,
Logger,
Patch,
Res,
UseGuards,
Expand Down Expand Up @@ -61,6 +62,7 @@ export class UserController {
throw new BadRequestException(ErrorMessage.UserAlreadyExists);
}

Logger.error(error);
throw new InternalServerErrorException(error);
}
}
Expand Down

0 comments on commit 4baecb2

Please sign in to comment.