mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: better training validation output
This commit is contained in:
1 parent
9a44422522
commit
6bda0e58d3
9 files changed
+13
-6
No files matched your search
@@ -107,7 +107,7 @@ export const ProblemDataNotFoundError = Err('ProblemDataNotFoundError', NotFound
|
||||
export const MessageNotFoundError = Err('MessageNotFoundError', NotFoundError, 'Message {0} not found.');
|
||||
export const DocumentNotFoundError = Err('DocumentNotFoundError', NotFoundError, 'Document {2} not found.');
|
||||
|
||||
export const ProblemNotFoundError = Err('ProblemNotFountError', DocumentNotFoundError, 'Problem {1} not found.');
|
||||
export const ProblemNotFoundError = Err('ProblemNotFoundError', DocumentNotFoundError, 'Problem {1} not found.');
|
||||
export const SolutionNotFoundError = Err('SolutionNotFoundError', DocumentNotFoundError, 'Solution {1} not found.');
|
||||
export const TrainingNotFoundError = Err('TrainingNotFoundError', DocumentNotFoundError, 'Training {1} not found.');
|
||||
export const ContestNotFoundError = Err('ContestNotFoundError', DocumentNotFoundError, 'Contest {1} not found.');
|
||||
|
||||
@@ -49,7 +49,7 @@ async function _parseDagJson(domainId: string, _dag: string): Promise<Tdoc['dag'
|
||||
parsed.push(newNode);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new ValidationError('dag', null, e.message);
|
||||
throw new ValidationError('dag', null, e instanceof ProblemNotFoundError ? e : e.message);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@@ -202,6 +202,7 @@ export class ProblemModel {
|
||||
static async copy(domainId: string, _id: number, target: string, pid?: string) {
|
||||
const original = await ProblemModel.get(domainId, _id);
|
||||
if (!original) throw new ProblemNotFoundError(domainId, _id);
|
||||
// TODO: refuse to copy referenced problem
|
||||
if (pid && (/^[0-9]+$/.test(pid) || await ProblemModel.get(target, pid))) pid = '';
|
||||
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
|
||||
const docId = await ProblemModel.add(
|
||||
|
||||
@@ -51,7 +51,7 @@ export default (logger) => async (ctx: KoaContext, next) => {
|
||||
if (request.json) response.body = { error };
|
||||
else {
|
||||
try {
|
||||
await ctx.render(error instanceof UserFacingError ? 'error.html' : 'bsod.html', { error });
|
||||
await ctx.render(error instanceof UserFacingError ? 'error.html' : 'bsod.html', { UserFacingError, error });
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
// this.response.body.error = {};
|
||||
|
||||
@@ -246,6 +246,7 @@ export class Handler extends HandlerCommon {
|
||||
this.response.status = error instanceof UserFacingError ? error.code : 500;
|
||||
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
|
||||
this.response.body = {
|
||||
UserFacingError,
|
||||
error: { message: error.msg(), params: error.params, stack: errorMessage(error.stack || '') },
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user