Skip to content

Commit

Permalink
add error catcher
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe committed Jun 15, 2024
1 parent 7994c74 commit eed435e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"lodash": "^4.17.21",
"nedb-promises": "^6.2.3",
"schemastery": "^3.14.6",
"superagent": "^8.1.2",
"superagent": "^9.0.2",
"unix-print": "^1.3.2",
"ws": "^8.17.0"
}
Expand Down
17 changes: 15 additions & 2 deletions packages/server/service/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ import { config } from '../config';
import { Logger, mongoId } from '../utils';

const logger = new Logger('fetcher');
const fetch = (url: string, type: 'get' | 'post' = 'get') => superagent[type](new URL(url, config.server).toString())
.set('Authorization', config.token).set('Accept', 'application/json');
const fetch = (url: string, type: 'get' | 'post' = 'get') => {
const endpoint = new URL(url, config.server).toString();
const req = superagent[type](endpoint)
.set('Authorization', config.token)
.set('Accept', 'application/json');
return new Proxy(req, {
get(target, prop) {
if (prop === 'then') {
return (...args) => target.then(...args)
.catch((e) => { throw new Error(`Failed to ${type} ${endpoint}: ${e.message}`); });
}
return req[prop];
},
});
};
export interface IBasicFetcher {
contest: Record<string, any>
cron(): Promise<void>
Expand Down
1 change: 0 additions & 1 deletion packages/ui/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const compiler = webpack({
},
{
test: /\.[mc]?[jt]sx?$/,
exclude: [/@types\//, /components\/message\//, /entry\.js/],
type: 'javascript/auto',
use: [esbuildLoader()],
},
Expand Down
20 changes: 10 additions & 10 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"preferUnplugged": true,
"devDependencies": {
"@hydrooj/xcpc-tools": "workspace:*",
"@mantine/code-highlight": "^7.10.1",
"@mantine/core": "^7.10.1",
"@mantine/form": "^7.10.1",
"@mantine/hooks": "^7.10.1",
"@mantine/modals": "^7.10.1",
"@mantine/notifications": "^7.10.1",
"@mantine/nprogress": "^7.10.1",
"@mantine/code-highlight": "^7.10.2",
"@mantine/core": "^7.10.2",
"@mantine/form": "^7.10.2",
"@mantine/hooks": "^7.10.2",
"@mantine/modals": "^7.10.2",
"@mantine/notifications": "^7.10.2",
"@mantine/nprogress": "^7.10.2",
"@tabler/icons-react": "^2.47.0",
"@tanstack/react-query": "^5.44.0",
"@tanstack/react-query": "^5.45.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"css-loader": "^6.11.0",
"esbuild-loader": "^2.21.0",
"esbuild-loader": "^4.1.0",
"mpegts.js": "^1.7.3",
"postcss": "^8.4.38",
"postcss-loader": "^7.3.3",
Expand All @@ -33,7 +33,7 @@
"react-router-dom": "^6.23.1",
"style-loader": "^3.3.4",
"webpack": "^5.92.0",
"webpack-dev-server": "^4.15.2",
"webpack-dev-server": "^5.0.4",
"webpackbar": "^6.0.1"
}
}

0 comments on commit eed435e

Please sign in to comment.