Skip to content

Commit

Permalink
Add timeout for http request
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukaola authored and jingyu committed May 2, 2022
1 parent dd32ab9 commit 4a4b6bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/defaultdidadapter.ts
Expand Up @@ -142,26 +142,28 @@ export class DefaultDIDAdapter implements DIDAdapter {
"Content-Type": "application/json",
"Accept": "application/json"
},
data: body
data: body,
timeout: 6000, // only wait for 6s
}).then((response) => {
if (response.status >= 200 && response.status < 400) {
resolve(response.data);
}
else {
reject(new ResolveException("HTTP error: " + response.statusText));
}
})
}).catch(error => {
reject(new ResolveException("HTTP timeout"));
});
});
}

public resolve(request: string): Promise<JSONObject> {
public async resolve(request: string): Promise<JSONObject> {
checkArgument(request && request != null, "Invalid request");

try {
return this.performRequest(this.rpcEndpoint, request);
return await this.performRequest(this.rpcEndpoint, request);
} catch (e) {
// IOException
throw new NetworkException("Network error.", e);
throw new NetworkException("Network error.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/backend/web3adapter.ts
Expand Up @@ -56,7 +56,7 @@ export class Web3Adapter extends DefaultDIDAdapter {
}

public async createIdTransaction(payload: string, memo: string) {
let web3 = new Web3(this.rpcEndpoint.toString());
let web3 = new Web3(super.rpcEndpoint.toString());
let contract = new web3.eth.Contract(PUBLISH_CONTRACT_ABI, this.contractAddress);

// PRIVNET WALLET WITH FUNDS TO PUBLISH - TODO: MAKE THIS BE A ENV DATA, NOT PUSHED.
Expand Down

0 comments on commit 4a4b6bf

Please sign in to comment.