Skip to content

Commit eed435e

Browse files
committed
add error catcher
1 parent 7994c74 commit eed435e

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"lodash": "^4.17.21",
2626
"nedb-promises": "^6.2.3",
2727
"schemastery": "^3.14.6",
28-
"superagent": "^8.1.2",
28+
"superagent": "^9.0.2",
2929
"unix-print": "^1.3.2",
3030
"ws": "^8.17.0"
3131
}

packages/server/service/fetcher.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ import { config } from '../config';
55
import { Logger, mongoId } from '../utils';
66

77
const logger = new Logger('fetcher');
8-
const fetch = (url: string, type: 'get' | 'post' = 'get') => superagent[type](new URL(url, config.server).toString())
9-
.set('Authorization', config.token).set('Accept', 'application/json');
8+
const fetch = (url: string, type: 'get' | 'post' = 'get') => {
9+
const endpoint = new URL(url, config.server).toString();
10+
const req = superagent[type](endpoint)
11+
.set('Authorization', config.token)
12+
.set('Accept', 'application/json');
13+
return new Proxy(req, {
14+
get(target, prop) {
15+
if (prop === 'then') {
16+
return (...args) => target.then(...args)
17+
.catch((e) => { throw new Error(`Failed to ${type} ${endpoint}: ${e.message}`); });
18+
}
19+
return req[prop];
20+
},
21+
});
22+
};
1023
export interface IBasicFetcher {
1124
contest: Record<string, any>
1225
cron(): Promise<void>

packages/ui/build.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const compiler = webpack({
6767
},
6868
{
6969
test: /\.[mc]?[jt]sx?$/,
70-
exclude: [/@types\//, /components\/message\//, /entry\.js/],
7170
type: 'javascript/auto',
7271
use: [esbuildLoader()],
7372
},

packages/ui/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
"preferUnplugged": true,
1111
"devDependencies": {
1212
"@hydrooj/xcpc-tools": "workspace:*",
13-
"@mantine/code-highlight": "^7.10.1",
14-
"@mantine/core": "^7.10.1",
15-
"@mantine/form": "^7.10.1",
16-
"@mantine/hooks": "^7.10.1",
17-
"@mantine/modals": "^7.10.1",
18-
"@mantine/notifications": "^7.10.1",
19-
"@mantine/nprogress": "^7.10.1",
13+
"@mantine/code-highlight": "^7.10.2",
14+
"@mantine/core": "^7.10.2",
15+
"@mantine/form": "^7.10.2",
16+
"@mantine/hooks": "^7.10.2",
17+
"@mantine/modals": "^7.10.2",
18+
"@mantine/notifications": "^7.10.2",
19+
"@mantine/nprogress": "^7.10.2",
2020
"@tabler/icons-react": "^2.47.0",
21-
"@tanstack/react-query": "^5.44.0",
21+
"@tanstack/react-query": "^5.45.0",
2222
"@types/react": "^18.3.3",
2323
"@types/react-dom": "^18.3.0",
2424
"css-loader": "^6.11.0",
25-
"esbuild-loader": "^2.21.0",
25+
"esbuild-loader": "^4.1.0",
2626
"mpegts.js": "^1.7.3",
2727
"postcss": "^8.4.38",
2828
"postcss-loader": "^7.3.3",
@@ -33,7 +33,7 @@
3333
"react-router-dom": "^6.23.1",
3434
"style-loader": "^3.3.4",
3535
"webpack": "^5.92.0",
36-
"webpack-dev-server": "^4.15.2",
36+
"webpack-dev-server": "^5.0.4",
3737
"webpackbar": "^6.0.1"
3838
}
3939
}

0 commit comments

Comments
 (0)