mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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",
|
"name": "hydrooj",
|
||||||
"version": "2.30.0",
|
"version": "2.30.1",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
/* eslint-disable func-names */
|
/* eslint-disable func-names */
|
||||||
import { isClass } from './utils';
|
|
||||||
|
|
||||||
interface IHydroError {
|
interface IHydroError {
|
||||||
new(...args: any[]): HydroError
|
new(...args: any[]): HydroError
|
||||||
}
|
}
|
||||||
|
|
||||||
function isHydroError(item: any): item is IHydroError {
|
const Err = (name: string, Class: IHydroError, ...info: Array<(() => string) | string | number>) => {
|
||||||
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;
|
|
||||||
let msg: () => string;
|
let msg: () => string;
|
||||||
let code: number;
|
let code: number;
|
||||||
for (const item of info) {
|
for (const item of info) {
|
||||||
@@ -20,26 +13,14 @@ const Err = (name: string, ...info: Array<IHydroError | (() => string) | ((_supe
|
|||||||
code = item;
|
code = item;
|
||||||
} else if (typeof item === 'string') {
|
} else if (typeof item === 'string') {
|
||||||
msg = function () { return item; };
|
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') {
|
} else if (typeof item === 'function') {
|
||||||
// @ts-ignore
|
msg = item;
|
||||||
constr = item;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const HydroError = class extends Class { };
|
const HydroError = class extends Class { };
|
||||||
HydroError.prototype.name = name;
|
HydroError.prototype.name = name;
|
||||||
if (msg) HydroError.prototype.msg = msg;
|
if (msg) HydroError.prototype.msg = msg;
|
||||||
if (code) HydroError.prototype.code = code;
|
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;
|
return HydroError;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,7 +30,7 @@ export class HydroError extends Error {
|
|||||||
|
|
||||||
constructor(...params: any[]) {
|
constructor(...params: any[]) {
|
||||||
super();
|
super();
|
||||||
this.params = params;
|
this.params = params || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
// eslint-disable-next-line class-methods-use-this
|
||||||
|
|||||||
@@ -311,12 +311,13 @@ export class HandlerCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkPerm(...args: bigint[]) {
|
checkPerm(...args: bigint[]) {
|
||||||
// @ts-ignore
|
if (!this.user.hasPerm(...args)) {
|
||||||
if (!this.user.hasPerm(...args)) throw new PermissionError(...args);
|
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) throw new PermissionError(...args);
|
||||||
|
throw new PrivilegeError(PRIV.PRIV_USER_PROFILE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPriv(...args: number[]) {
|
checkPriv(...args: number[]) {
|
||||||
// @ts-ignore
|
|
||||||
if (!this.user.hasPriv(...args)) throw new PrivilegeError(...args);
|
if (!this.user.hasPriv(...args)) throw new PrivilegeError(...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ if (cluster.isMaster) {
|
|||||||
});
|
});
|
||||||
if (process.env.NODE_ENV !== 'test') {
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
process.stdin.setEncoding('utf-8');
|
process.stdin.setEncoding('utf-8');
|
||||||
process.stdin.setRawMode(false);
|
if (process.stdin.setRawMode) process.stdin.setRawMode(false);
|
||||||
process.stdin.on('data', (buf) => {
|
process.stdin.on('data', (buf) => {
|
||||||
const input = buf.toString();
|
const input = buf.toString();
|
||||||
if (input[0] === '@') {
|
if (input[0] === '@') {
|
||||||
|
|||||||
Reference in new issue
Block a user