Skip to content

Commit

Permalink
refactor: remove unnecessary logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiwon-Woo committed Jan 24, 2024
1 parent 3ac3a5c commit 6569795
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 458 deletions.
1 change: 0 additions & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class AuthService {
const accessToken: string = await this.generateToken(user);
return { accessToken };
} catch (error) {
this.logger.error(`refreshAccessToken [error: ${error.message}]`);
throw new UnauthorizedException('Unauthorized', '401');
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/auth/guard/jwt.guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, ExecutionContext, Logger } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { JwtService } from '@nestjs/jwt';
import { UnknownException } from 'src/common/exception/unknown.exception';

@Injectable()
export class JwtGuard extends AuthGuard('jwt') {
Expand Down Expand Up @@ -35,7 +36,7 @@ export class JwtGuard extends AuthGuard('jwt') {
token could be expired or invaild
return exception to client and let client to refresh token
*/
throw error;
throw new UnknownException(error);
}
this.logger.debug(`canActivate [result: ${result}]`);
return result;
Expand Down
1 change: 0 additions & 1 deletion src/auth/strategy/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
try {
done(null, payload);
} catch (error) {
this.logger.error(`validate [error: ${error.message}]`);
throw new UnauthorizedException('Unauthorized', '401');
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/batch/batch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ export class BatchService {
try {
await this.meetupsService.createMatching({ meetupId, teamNum: 1 });
} catch (e) {
this.logger.error('[createWeeklyMeeting]', e);
this.logger.error(`[createWeeklyMeeting] meetupId: ${meetupId}`);
this.logger.error(e);
}
},
});
this.logger.debug(`[createWeeklyMeeting] matchWeeklyMeeting: `, cronJob);
this.schedulerReistry.addCronJob('matchWeeklyMeeting', cronJob);
cronJob.start();
}
Expand All @@ -60,10 +62,12 @@ export class BatchService {
try {
await this.meetupsService.createMatching({ meetupId, teamNum: 1 });
} catch (e) {
this.logger.error('[createWeeklyDinner]', e);
this.logger.error(`[createWeeklyDinner] meetupId: ${meetupId}`);
this.logger.error(e);
}
},
});
this.logger.debug(`[createWeeklyDinner] matchWeeklyDinner: `, cronJob);
this.schedulerReistry.addCronJob('matchWeeklyDinner', cronJob);
cronJob.start();
}
Expand Down
4 changes: 3 additions & 1 deletion src/common/enum/error-message.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export enum ErrorMessage {
MEETUP_REGISTRATION_ALREADY_EXIST = '이미 신청한 이벤트 입니다.',
TOO_MANY_MEETUP_TEAM_NUMBER = '신청 인원보다 팀 개수가 많습니다.',

USER_NOT_FOUND = '존재하지 않는 유저입니다.'
USER_NOT_FOUND = '존재하지 않는 유저입니다.',

HASH_TOKEN_ERROR = 'HASH_TOKEN_ERROR'
}

export type KeyOfErrorMessage = keyof typeof ErrorMessage;
60 changes: 25 additions & 35 deletions src/holiday/holiday.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,41 @@ export class HolidayService {
timeZone: 'Asia/Seoul',
})
async saveHolidayInfo(): Promise<void> {
try {
this.logger.log('Fetching holiday info...');
this.logger.log('Fetching holiday info...');

const holidayArray: HolidayInfo[] = await getHolidayArray();
const holidayArray: HolidayInfo[] = await getHolidayArray();

if (holidayArray === null) {
return;
}
if (holidayArray === null) {
return;
}

for (const holidayInfo of holidayArray) {
const { year, month, day, info } = holidayInfo;
for (const holidayInfo of holidayArray) {
const { year, month, day, info } = holidayInfo;

const recordExist = await this.holidayRepository.findOne({
where: {
year,
month,
day,
},
});
const recordExist = await this.holidayRepository.findOne({
where: {
year,
month,
day,
},
});

if (recordExist) {
continue;
}
if (recordExist) {
continue;
}

const newHoliday = new RotationHolidayEntity();
newHoliday.year = year;
newHoliday.month = month;
newHoliday.day = day;
newHoliday.info = info;
const newHoliday = new RotationHolidayEntity();
newHoliday.year = year;
newHoliday.month = month;
newHoliday.day = day;
newHoliday.info = info;

await this.holidayRepository.save(newHoliday);
}
this.logger.log('Successfully stored holiday info!');
} catch (error: any) {
this.logger.error(error);
throw error;
await this.holidayRepository.save(newHoliday);
}
this.logger.log('Successfully stored holiday info!');
}

async getHolidayByYearAndMonth(year: number, month: number): Promise<number[]> {
try {
return await this.myHolidayRepository.findHolidayByYearAndMonth(year, month);
} catch (error: any) {
this.logger.error(error);
throw error;
}
return await this.myHolidayRepository.findHolidayByYearAndMonth(year, month);
}
}
29 changes: 11 additions & 18 deletions src/holiday/repository/holiday.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@ export class HolidayRepository extends Repository<RotationHolidayEntity> {
super(RotationHolidayEntity, dataSource.createEntityManager());
}

async findHolidayByYearAndMonth(
year: number,
month: number,
): Promise<number[]> {
try {
const records = await this.find({
where: {
year: year,
month: month,
},
});
async findHolidayByYearAndMonth(year: number, month: number): Promise<number[]> {
const records = await this.find({
where: {
year: year,
month: month,
},
});

if (records.length === 0) {
return [];
}

return records.map((record) => record.day);
} catch (error: any) {
throw new Error(`Error occurred in findHolidayByYearAndMonth: ${error}`);
if (records.length === 0) {
return [];
}

return records.map((record) => record.day);
}
}
4 changes: 2 additions & 2 deletions src/middleware/google.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, NestMiddleware, Logger } from '@nestjs/common';
import { Injectable, NestMiddleware, Logger, InternalServerErrorException } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import axios from 'axios';

Expand Down Expand Up @@ -28,7 +28,7 @@ export class GoogleMiddleware implements NestMiddleware {
);
const userInfo = response.data;
if (!userInfo) {
throw new Error('Invalid token');
throw new InternalServerErrorException('Invalid Google Token');
}
req['user'] = userInfo;
next();
Expand Down
Loading

0 comments on commit 6569795

Please sign in to comment.