Skip to content

Commit

Permalink
chore : GreenEyeService에 로그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sk000801 committed Dec 6, 2023
1 parent 30189ff commit 05e1d4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
37 changes: 21 additions & 16 deletions server/src/config/greenEye.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { CatchyException } from 'src/config/catchyException';
import { ERROR_CODE } from 'src/config/errorCode.enum';
import { GreenEyeResponseDto } from 'src/dto/greenEye.response.dto';
import { HTTP_STATUS_CODE } from 'src/httpStatusCode.enum';
import { Logger } from '@nestjs/common';

@Injectable()
export class GreenEyeService {
private readonly logger = new Logger('GreenEyeService');
greenEyeSecretKey: string;
greenEyeRequestUrl: string;

Expand All @@ -23,9 +25,7 @@ export class GreenEyeService {
return new Date().getTime();
}

private getRequestInit(
imageUrl: string,
): Record<string, string | Record<string, string>> {
private getRequestInit(imageUrl: string): RequestInit {
return {
method: 'POST',
headers: {
Expand All @@ -47,18 +47,23 @@ export class GreenEyeService {
}

async getResultOfNormalImage(imageUrl: string): Promise<GreenEyeResponseDto> {
try {
return await fetch(this.greenEyeRequestUrl, this.getRequestInit(imageUrl))
.then((res) => res.json())
.catch((err) => {
throw new Error();
});
} catch {
throw new CatchyException(
'INVALID_GREEN_EYE_REQUEST',
HTTP_STATUS_CODE.BAD_REQUEST,
ERROR_CODE.INVALID_GREEN_EYE_REQUEST,
);
}
return await fetch(this.greenEyeRequestUrl, this.getRequestInit(imageUrl))
.then((res) => {
if (res.ok) {
return res.json();
}

throw new Error();
})
.catch((err) => {
this.logger.error(
`greenEye.service - getResultOfNormalImage : INVALID_GREEN_EYE_REQUEST`,
);
throw new CatchyException(
'INVALID_GREEN_EYE_REQUEST',
HTTP_STATUS_CODE.BAD_REQUEST,
ERROR_CODE.INVALID_GREEN_EYE_REQUEST,
);
});
}
}
8 changes: 1 addition & 7 deletions server/src/upload/upload.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, Logger, LoggerService } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { HTTP_STATUS_CODE } from 'src/httpStatusCode.enum';
import { NcloudConfigService } from './../config/ncloud.config';
import { S3 } from 'aws-sdk';
Expand Down Expand Up @@ -170,12 +170,6 @@ export class UploadService {
return { url: uploadResult.Location };
} catch (err) {
if (err instanceof CatchyException) {
if (err.message === 'INVALID_GREEN_EYE_REQUEST') {
this.logger.error(
`greenEye.service - getResultOfNormalImage : INVALID_GREEN_EYE_REQUEST`,
);
}

throw err;
}

Expand Down

0 comments on commit 05e1d4c

Please sign in to comment.