core&ui: add error & fix error notification (#464)

This commit is contained in:
panda authored and GitHub committed 2022-11-26 20:30:18 +08:00
1 parent a2ea3812df
commit 534a634028
14 files changed
+123 -76

No files matched your search

+2 -2
View File
@@ -2,7 +2,7 @@ import { escapeRegExp, pick } from 'lodash';
import { FilterQuery, ObjectID } from 'mongodb';
import type { Readable } from 'stream';
import { streamToBuffer } from '@hydrooj/utils/lib/utils';
import { ProblemNotFoundError, ValidationError } from '../error';
import { FileUploadError, ProblemNotFoundError, ValidationError } from '../error';
import type {
Document, ProblemDict, ProblemStatusDoc, User,
} from '../interface';
@@ -245,7 +245,7 @@ export class ProblemModel {
storage.put(`problem/${domainId}/${pid}/testdata/${name}`, f, operator),
]);
const meta = await storage.getMeta(`problem/${domainId}/${pid}/testdata/${name}`);
if (!meta) throw new Error('Upload failed');
if (!meta) throw new FileUploadError();
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
payload.lastModified ||= new Date();
if (!fileinfo) await ProblemModel.push(domainId, pid, 'data', { _id: name, ...payload });