Handle CORS errors during WKD lookup (#1125)
Also, throw an error instead of returning null when the server returned an error status.
This commit is contained in:
parent
8783caa828
commit
de360e200c
12
src/wkd.js
12
src/wkd.js
|
@ -60,11 +60,17 @@ WKD.prototype.lookup = async function(options) {
|
||||||
const urlAdvanced = `https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${localEncoded}`;
|
const urlAdvanced = `https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${localEncoded}`;
|
||||||
const urlDirect = `https://${domain}/.well-known/openpgpkey/hu/${localEncoded}`;
|
const urlDirect = `https://${domain}/.well-known/openpgpkey/hu/${localEncoded}`;
|
||||||
|
|
||||||
let response = await fetch(urlAdvanced);
|
let response;
|
||||||
if (response.status !== 200) {
|
try {
|
||||||
|
response = await fetch(urlAdvanced);
|
||||||
|
if (response.status !== 200) {
|
||||||
|
throw new Error('Advanced WKD lookup failed: ' + response.statusText);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
util.print_debug_error(err);
|
||||||
response = await fetch(urlDirect);
|
response = await fetch(urlDirect);
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
return;
|
throw new Error('Direct WKD lookup failed: ' + response.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user