@iexec/web3mail
Version:
This product enables users to confidentially store data–such as mail address, documents, personal information ...
37 lines • 1.54 kB
JavaScript
import { CompassCallError } from 'iexec/errors';
export async function resolveDappAddressFromCompass(compassUrl, chainId) {
if (!compassUrl) {
return undefined;
}
const address = await fetch(`${compassUrl}/${chainId}/iapps/web3mail-tdx`)
// Handle network errors
.catch((error) => {
throw new CompassCallError(`Connection to ${compassUrl} failed with a network error`, error);
})
// Handle server errors
.then((response) => {
if (response.status >= 500 && response.status <= 599) {
throw new CompassCallError(`Server at ${compassUrl} encountered an internal error`, Error(`Server internal error: ${response.status} ${response.statusText}`));
}
return response;
})
// Handle unexpected response formats
.then((response) => {
if (response.status !== 200) {
throw new Error(`Failed to fetch dapp address from compass: ${response.statusText}`);
}
const contentType = response.headers.get('Content-Type');
if (!contentType || contentType.indexOf('application/json') === -1) {
throw new Error('Failed to fetch dapp address from compass: response is not JSON');
}
return response.json();
})
.then((data) => {
if (!data || !data.address) {
throw new Error(`No dapp address found in compass response`);
}
return data.address;
});
return address;
}
//# sourceMappingURL=resolveDappAddressFromCompass.js.map