From 71c1226515a7de6c6b9c54ed40d3e75c65a9ccdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E9=99=90UCW?= <45730483+wuxianucw@users.noreply.github.com> Date: Sat, 17 Apr 2021 22:21:43 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E8=B0=83=E6=95=B4=20Error=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20(#94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrooj/src/handler/contest.ts | 2 +- packages/hydrooj/src/handler/discussion.ts | 8 ++++---- packages/hydrooj/src/handler/problem.ts | 2 +- packages/hydrooj/src/model/contest.ts | 2 +- packages/hydrooj/src/model/discussion.ts | 2 +- packages/hydrooj/src/model/solution.ts | 2 +- packages/hydrooj/src/model/training.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/hydrooj/src/handler/contest.ts b/packages/hydrooj/src/handler/contest.ts index 45c2c5edd..bdc70fed2 100644 --- a/packages/hydrooj/src/handler/contest.ts +++ b/packages/hydrooj/src/handler/contest.ts @@ -261,7 +261,7 @@ class ContestProblemHandler extends ContestHandler { if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(this.tdoc.docId); } if (!this.tdoc.pids.map((s) => s.toString()).includes(this.pdoc.docId.toString())) { - throw new ProblemNotFoundError(pid, this.tdoc.docId); + throw new ProblemNotFoundError(domainId, this.tdoc.docId); } } diff --git a/packages/hydrooj/src/handler/discussion.ts b/packages/hydrooj/src/handler/discussion.ts index 8d9fea22b..9f1a2a439 100644 --- a/packages/hydrooj/src/handler/discussion.ts +++ b/packages/hydrooj/src/handler/discussion.ts @@ -42,17 +42,17 @@ class DiscussionHandler extends Handler { this.checkPerm(PERM.PERM_VIEW_DISCUSSION); if (did) { this.ddoc = await discussion.get(domainId, did); - if (!this.ddoc) throw new DiscussionNotFoundError(did); + if (!this.ddoc) throw new DiscussionNotFoundError(domainId, did); type = discussion.typeDisplay[this.ddoc.parentType]; name = this.ddoc.parentId.toString(); if (drrid) { [this.drdoc, this.drrdoc] = await discussion.getTailReply(domainId, drid, drrid); - if (!this.drrdoc) throw new DiscussionNotFoundError(drrid); + if (!this.drrdoc) throw new DiscussionNotFoundError(domainId, drrid); } else if (drid) { this.drdoc = await discussion.getReply(domainId, drid); - if (!this.drdoc) throw new DiscussionNotFoundError(drid); + if (!this.drdoc) throw new DiscussionNotFoundError(domainId, drid); if (!this.drdoc.parentId.equals(this.ddoc._id)) { - throw new DocumentNotFoundError(drid); + throw new DocumentNotFoundError(domainId, drid); } } } diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index ee352707f..6d0fe92c6 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -510,7 +510,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler { @param('content', Types.Content) async postEditReply(domainId: string, psid: ObjectID, psrid: ObjectID, content: string) { const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid); - if ((!psdoc) || psdoc.pid !== this.pdoc.docId) throw new SolutionNotFoundError(psid); + if ((!psdoc) || psdoc.pid !== this.pdoc.docId) throw new SolutionNotFoundError(domainId, psid); if (!(psrdoc.owner === this.user._id && this.user.hasPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION_REPLY_SELF))) { throw new PermissionError(PERM.PERM_EDIT_PROBLEM_SOLUTION_REPLY_SELF); diff --git a/packages/hydrooj/src/model/contest.ts b/packages/hydrooj/src/model/contest.ts index 85da111a7..746e1121d 100644 --- a/packages/hydrooj/src/model/contest.ts +++ b/packages/hydrooj/src/model/contest.ts @@ -380,7 +380,7 @@ export async function edit( if (!this.RULES[$set.rule]) throw new ValidationError('rule'); } const tdoc = await document.get(domainId, type, tid); - if (!tdoc) throw new ContestNotFoundError(tid); + if (!tdoc) throw new ContestNotFoundError(domainId, tid); this.RULES[$set.rule || tdoc.rule].check(Object.assign(tdoc, $set)); return await document.set(domainId, type, tid, $set); } diff --git a/packages/hydrooj/src/model/discussion.ts b/packages/hydrooj/src/model/discussion.ts index 24492fee1..c8cb86a6d 100644 --- a/packages/hydrooj/src/model/discussion.ts +++ b/packages/hydrooj/src/model/discussion.ts @@ -153,7 +153,7 @@ export async function editReply( export async function delReply(domainId: string, drid: ObjectID) { const drdoc = await getReply(domainId, drid); - if (!drdoc) throw new DocumentNotFoundError(drid); + if (!drdoc) throw new DocumentNotFoundError(domainId, drid); return await Promise.all([ document.deleteOne(domainId, document.TYPE_DISCUSSION_REPLY, drid), document.inc(domainId, document.TYPE_DISCUSSION, drdoc.parentId, 'nReply', -1), diff --git a/packages/hydrooj/src/model/solution.ts b/packages/hydrooj/src/model/solution.ts index c29178c6e..082254512 100644 --- a/packages/hydrooj/src/model/solution.ts +++ b/packages/hydrooj/src/model/solution.ts @@ -13,7 +13,7 @@ class SolutionModel { static async get(domainId: string, psid: ObjectID) { const psdoc = await document.get(domainId, document.TYPE_PROBLEM_SOLUTION, psid); - if (!psdoc) throw new SolutionNotFoundError(); + if (!psdoc) throw new SolutionNotFoundError(domainId, psid); return psdoc; } diff --git a/packages/hydrooj/src/model/training.ts b/packages/hydrooj/src/model/training.ts index 2707f58de..1253c34f3 100644 --- a/packages/hydrooj/src/model/training.ts +++ b/packages/hydrooj/src/model/training.ts @@ -93,7 +93,7 @@ export async function count(domainId: string, query: FilterQuery) { export async function get(domainId: string, tid: ObjectID) { const tdoc = await document.get(domainId, document.TYPE_TRAINING, tid); - if (!tdoc) throw new TrainingNotFoundError(tid); + if (!tdoc) throw new TrainingNotFoundError(domainId, tid); for (const i in tdoc.dag) { for (const j in tdoc.dag[i].pids) { if (Number.isSafeInteger(parseInt(tdoc.dag[i].pids[j], 10))) {