Skip to content

Commit eddba96

Browse files
committed
show error body
1 parent eed435e commit eddba96

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/server/service/fetcher.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ const fetch = (url: string, type: 'get' | 'post' = 'get') => {
99
const endpoint = new URL(url, config.server).toString();
1010
const req = superagent[type](endpoint)
1111
.set('Authorization', config.token)
12-
.set('Accept', 'application/json');
12+
.set('Accept', 'application/json')
13+
.ok(() => true);
1314
return new Proxy(req, {
1415
get(target, prop) {
1516
if (prop === 'then') {
16-
return (...args) => target.then(...args)
17-
.catch((e) => { throw new Error(`Failed to ${type} ${endpoint}: ${e.message}`); });
17+
return (...args) => target.then((res) => {
18+
if (res.status !== 200) throw new Error(`Failed to ${type} ${endpoint} : ${res.status} - ${JSON.stringify(res.body || {})}`);
19+
return res;
20+
}).then(...args);
1821
}
1922
return req[prop];
2023
},
@@ -52,7 +55,7 @@ class BasicFetcher extends Service implements IBasicFetcher {
5255
async contestInfo() {
5356
const old = this?.contest?.id;
5457
this.contest = { name: 'No Contest', id: 'server-mode' };
55-
return old === this.contest.id;
58+
return old !== this.contest.id;
5659
}
5760

5861
async getToken(username, password) {
@@ -97,7 +100,7 @@ class DOMjudgeFetcher extends BasicFetcher {
97100
const old = this?.contest?.id;
98101
this.contest = { info: contest, id: contest.id, name: contest.name };
99102
logger.info(`Connected to ${contest.name}(id=${contest.id})`);
100-
return old === this.contest.id;
103+
return old !== this.contest.id;
101104
}
102105

103106
async teamInfo() {

0 commit comments

Comments
 (0)