mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
framework: fix unwrapAggregatedError
This commit is contained in:
1 parent
73b2e4d75d
commit
a7a49bf791
4 files changed
+12
-8
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/framework",
|
"name": "@hydrooj/framework",
|
||||||
"version": "0.3.1",
|
"version": "0.3.2",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro",
|
"repository": "https://github.com/hydro-dev/Hydro",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Schema from 'schemastery';
|
|||||||
import { Shorty } from 'shorty.js';
|
import { Shorty } from 'shorty.js';
|
||||||
import { WebSocket, WebSocketServer } from 'ws';
|
import { WebSocket, WebSocketServer } from 'ws';
|
||||||
import {
|
import {
|
||||||
Counter, errorMessage, isClass, Logger, parseMemoryMB,
|
Counter, errorMessage, isClass, Logger, parseMemoryMB, unwrapAggregateError,
|
||||||
} from '@hydrooj/utils/lib/utils';
|
} from '@hydrooj/utils/lib/utils';
|
||||||
import base from './base';
|
import base from './base';
|
||||||
import * as decorators from './decorators';
|
import * as decorators from './decorators';
|
||||||
@@ -56,10 +56,6 @@ async function forkContextWithScope(ctx: CordisContext) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function unwrapAggregateError(error: any) {
|
|
||||||
return error instanceof AggregateError ? error.errors[0] : error;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface HydroRequest {
|
export interface HydroRequest {
|
||||||
method: string;
|
method: string;
|
||||||
host: string;
|
host: string;
|
||||||
@@ -259,6 +255,7 @@ export class Handler extends HandlerCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onerror(error: HydroError) {
|
async onerror(error: HydroError) {
|
||||||
|
error = unwrapAggregateError(error);
|
||||||
error.msg ||= () => error.message;
|
error.msg ||= () => error.message;
|
||||||
console.error(`Error on user request: ${error.msg()}\n`, error);
|
console.error(`Error on user request: ${error.msg()}\n`, error);
|
||||||
if (error instanceof UserFacingError && !process.env.DEV) error.stack = '';
|
if (error instanceof UserFacingError && !process.env.DEV) error.stack = '';
|
||||||
|
|||||||
@@ -170,8 +170,15 @@ export const Time = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function unwrapAggregateError(error: any): any {
|
||||||
|
return error instanceof Error && Array.isArray((error as any).errors) && (error as any).errors.length
|
||||||
|
? unwrapAggregateError((error as any).errors[0])
|
||||||
|
: error;
|
||||||
|
}
|
||||||
|
|
||||||
export function errorMessage(err: Error | string) {
|
export function errorMessage(err: Error | string) {
|
||||||
const t = typeof err === 'string' ? err : err.stack;
|
err = unwrapAggregateError(err);
|
||||||
|
const t = typeof err === 'string' ? err : err.stack || err.message || String(err);
|
||||||
const lines = t.split('\n')
|
const lines = t.split('\n')
|
||||||
.filter((i) => !i.includes(' (node:') && !i.includes('(internal'));
|
.filter((i) => !i.includes(' (node:') && !i.includes('(internal'));
|
||||||
let cursor = 1;
|
let cursor = 1;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/utils",
|
"name": "@hydrooj/utils",
|
||||||
"version": "1.5.7",
|
"version": "1.5.8",
|
||||||
"description": "hydrooj utils",
|
"description": "hydrooj utils",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "lib/utils.ts",
|
"main": "lib/utils.ts",
|
||||||
|
|||||||
Reference in new issue
Block a user