Skip to content

Commit

Permalink
fix: throw -> return으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yechan2468 committed Dec 5, 2023
1 parent f441735 commit 04e93bb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
8 changes: 6 additions & 2 deletions be/algo-with-me-score/src/score/services/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class FetchService {
this.logger.error(
`API 서버로 채점 결과를 보내는 데 실패했습니다 (POST ${url}) 원인: ${error}`,
);
throw new InternalServerErrorException();
}
}

Expand All @@ -52,7 +51,12 @@ export class FetchService {
this.logger.error(
`도커 서버로 채점 요청을 보내는 데 실패했습니다 (POST ${url}) 원인: ${error}`,
);
throw new InternalServerErrorException();
return {
result: 'Internal Server Error',
competitionId,
userId,
problemId,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ export class FilesystemService {
}
} catch (error) {
this.logger.error(error);
throw new InternalServerErrorException();
return false;
}

const codeFilepath = path.join(baseDirectory, `${problemId}.js`);
try {
fs.writeFileSync(codeFilepath, mergedCode);
} catch (error) {
this.logger.error(`실행 가능한 코드 파일(${codeFilepath})이 쓰이지 않았습니다`);
throw new InternalServerErrorException();
return false;
}
return true;
}

private getMergedCode(code: string, frameCode: string) {
Expand Down Expand Up @@ -83,7 +84,7 @@ export class FilesystemService {
const filepath = this.getTestcaseFilepath(problemId, testcaseId);
if (!fs.existsSync(filepath)) {
this.logger.error(`경로 ${filepath}에서 테스트케이스 ans 파일을 찾을 수 없습니다`);
throw new InternalServerErrorException();
return undefined;
}

return fs.readFileSync(filepath).toString().trim();
Expand Down
9 changes: 6 additions & 3 deletions be/algo-with-me-score/src/score/services/score.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export class SubmissionConsumer {
const { socketId, submissionId } = messageQueueItem;
const submission: Submission = await this.submissionRepository.findOneBy({ id: submissionId });
if (!submission) {
this.logger.error(`제출 id ${submissionId}에 해당하는 제출 정보를 찾을 수 없습니다`);
throw new InternalServerErrorException();
this.logger.error(
`Redis로부터 제출 요청을 받았지만, 제출 id ${submissionId}에 해당하는 제출 정보를 찾을 수 없습니다`,
);
return;
}

const problemId = submission.problemId;
Expand All @@ -41,12 +43,13 @@ export class SubmissionConsumer {
this.logger.debug(`채점 시작: ${JSON.stringify({ competitionId, userId, problemId })}`);

this.filesystemService.removeCodeRunOutputs(competitionId, userId);
await this.filesystemService.writeSubmittedCode(
const writeSucceeded = await this.filesystemService.writeSubmittedCode(
submission.code,
competitionId,
userId,
problemId,
);
if (!writeSucceeded) return;

const problem: Problem = await this.problemRepository.findOneBy({ id: problemId });
await this.scoreService.scoreAllAndSendResult(
Expand Down
3 changes: 2 additions & 1 deletion be/algo-with-me-score/src/score/services/score.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ScoreService {
containerId: number;
socketId: string;
}) {
const codeRunResponse = await this.fetchService.requestDockerServerToRunCode(
const codeRunResponse: ICoderunResponse = await this.fetchService.requestDockerServerToRunCode(
args.competitionId,
args.userId,
args.problemId,
Expand All @@ -69,6 +69,7 @@ export class ScoreService {
args.problemId,
args.testcaseId,
);
if (!testcaseAnswer) return;
const judgeResult = this.judge(codeRunResponse, codeRunOutput, testcaseAnswer, args);

const scoreResult = new ScoreResultDto(
Expand Down

0 comments on commit 04e93bb

Please sign in to comment.