framework: fix unwrapAggregatedError

This commit is contained in:
undefined committed 2026-09-03 07:56:49 +00:00
1 parent 73b2e4d75d
commit a7a49bf791
4 files changed
+12 -8

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/framework",
"version": "0.3.1",
"version": "0.3.2",
"main": "index.ts",
"license": "MIT",
"repository": "https://github.com/hydro-dev/Hydro",
+2 -5
View File
@@ -14,7 +14,7 @@ import Schema from 'schemastery';
import { Shorty } from 'shorty.js';
import { WebSocket, WebSocketServer } from 'ws';
import {
Counter, errorMessage, isClass, Logger, parseMemoryMB,
Counter, errorMessage, isClass, Logger, parseMemoryMB, unwrapAggregateError,
} from '@hydrooj/utils/lib/utils';
import base from './base';
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 {
method: string;
host: string;
@@ -259,6 +255,7 @@ export class Handler extends HandlerCommon {
}
async onerror(error: HydroError) {
error = unwrapAggregateError(error);
error.msg ||= () => error.message;
console.error(`Error on user request: ${error.msg()}\n`, error);
if (error instanceof UserFacingError && !process.env.DEV) error.stack = '';
+8 -1
View File
@@ -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) {
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')
.filter((i) => !i.includes(' (node:') && !i.includes('(internal'));
let cursor = 1;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/utils",
"version": "1.5.7",
"version": "1.5.8",
"description": "hydrooj utils",
"type": "module",
"main": "lib/utils.ts",