@@ -9,12 +9,15 @@ const fetch = (url: string, type: 'get' | 'post' = 'get') => {
9
9
const endpoint = new URL ( url , config . server ) . toString ( ) ;
10
10
const req = superagent [ type ] ( endpoint )
11
11
. set ( 'Authorization' , config . token )
12
- . set ( 'Accept' , 'application/json' ) ;
12
+ . set ( 'Accept' , 'application/json' )
13
+ . ok ( ( ) => true ) ;
13
14
return new Proxy ( req , {
14
15
get ( target , prop ) {
15
16
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 ) ;
18
21
}
19
22
return req [ prop ] ;
20
23
} ,
@@ -52,7 +55,7 @@ class BasicFetcher extends Service implements IBasicFetcher {
52
55
async contestInfo ( ) {
53
56
const old = this ?. contest ?. id ;
54
57
this . contest = { name : 'No Contest' , id : 'server-mode' } ;
55
- return old = == this . contest . id ;
58
+ return old ! == this . contest . id ;
56
59
}
57
60
58
61
async getToken ( username , password ) {
@@ -97,7 +100,7 @@ class DOMjudgeFetcher extends BasicFetcher {
97
100
const old = this ?. contest ?. id ;
98
101
this . contest = { info : contest , id : contest . id , name : contest . name } ;
99
102
logger . info ( `Connected to ${ contest . name } (id=${ contest . id } )` ) ;
100
- return old = == this . contest . id ;
103
+ return old ! == this . contest . id ;
101
104
}
102
105
103
106
async teamInfo ( ) {
0 commit comments