error handling

This commit is contained in:
Florian Dold 2019-12-28 16:21:21 +01:00
parent 7523dcab95
commit 3c85a0d14e
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -85,6 +85,10 @@ async function callBackend<T extends MessageType>(
): Promise<MessageMap[T]["response"]> {
return new Promise<MessageMap[T]["response"]>((resolve, reject) => {
chrome.runtime.sendMessage({ type, detail }, (resp) => {
if (chrome.runtime.lastError) {
console.log("Error calling backend");
reject(new Error(`Error contacting backend: chrome.runtime.lastError.message`));
}
if (typeof resp === "object" && resp && resp.error) {
console.warn("response error:", resp)
const e = new WalletApiError(resp.error.message, resp.error);