mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: 优化错误信息显示
This commit is contained in:
1 parent
10a1de0741
commit
4d6efdc37f
4 files changed
+9
-27
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.30.0",
|
||||
"version": "2.30.1",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-disable func-names */
|
||||
import { isClass } from './utils';
|
||||
|
||||
interface IHydroError {
|
||||
new(...args: any[]): HydroError
|
||||
}
|
||||
|
||||
function isHydroError(item: any): item is IHydroError {
|
||||
return isClass(item);
|
||||
}
|
||||
|
||||
const Err = (name: string, ...info: Array<IHydroError | (() => string) | ((_super: Function, ...args: any) => HydroError) | string | number>) => {
|
||||
let Class: IHydroError;
|
||||
let constr: (_super: Function, ...args: any[]) => HydroError;
|
||||
const Err = (name: string, Class: IHydroError, ...info: Array<(() => string) | string | number>) => {
|
||||
let msg: () => string;
|
||||
let code: number;
|
||||
for (const item of info) {
|
||||
@@ -20,26 +13,14 @@ const Err = (name: string, ...info: Array<IHydroError | (() => string) | ((_supe
|
||||
code = item;
|
||||
} else if (typeof item === 'string') {
|
||||
msg = function () { return item; };
|
||||
} else if (isHydroError(item)) {
|
||||
Class = item;
|
||||
} else if (typeof item === 'function' && item.length === 0) {
|
||||
// @ts-ignore
|
||||
msg = item;
|
||||
} else if (typeof item === 'function') {
|
||||
// @ts-ignore
|
||||
constr = item;
|
||||
msg = item;
|
||||
}
|
||||
}
|
||||
const HydroError = class extends Class { };
|
||||
HydroError.prototype.name = name;
|
||||
if (msg) HydroError.prototype.msg = msg;
|
||||
if (code) HydroError.prototype.code = code;
|
||||
if (constr) {
|
||||
const original = HydroError.prototype.constructor;
|
||||
HydroError.prototype.constructor = function (...args: any[]) {
|
||||
constr.call(this, original.bind(this, ...args));
|
||||
};
|
||||
}
|
||||
return HydroError;
|
||||
};
|
||||
|
||||
@@ -49,7 +30,7 @@ export class HydroError extends Error {
|
||||
|
||||
constructor(...params: any[]) {
|
||||
super();
|
||||
this.params = params;
|
||||
this.params = params || [];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
|
||||
@@ -311,12 +311,13 @@ export class HandlerCommon {
|
||||
}
|
||||
|
||||
checkPerm(...args: bigint[]) {
|
||||
// @ts-ignore
|
||||
if (!this.user.hasPerm(...args)) throw new PermissionError(...args);
|
||||
if (!this.user.hasPerm(...args)) {
|
||||
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) throw new PermissionError(...args);
|
||||
throw new PrivilegeError(PRIV.PRIV_USER_PROFILE);
|
||||
}
|
||||
}
|
||||
|
||||
checkPriv(...args: number[]) {
|
||||
// @ts-ignore
|
||||
if (!this.user.hasPriv(...args)) throw new PrivilegeError(...args);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ if (cluster.isMaster) {
|
||||
});
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
process.stdin.setEncoding('utf-8');
|
||||
process.stdin.setRawMode(false);
|
||||
if (process.stdin.setRawMode) process.stdin.setRawMode(false);
|
||||
process.stdin.on('data', (buf) => {
|
||||
const input = buf.toString();
|
||||
if (input[0] === '@') {
|
||||
|
||||
Reference in new issue
Block a user