From 9fe6dc596573f38b13f0b15c946b8bc16013fdd9 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 29 Jan 2018 18:59:45 +0100 Subject: [PATCH] better error handling --- src/webex/pages/confirm-contract.tsx | 1 - src/webex/pages/confirm-create-reserve.tsx | 22 +++++++++++----------- src/webex/wxApi.ts | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index 6089d0f8a..21f05d5d6 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -256,7 +256,6 @@ class ContractPrompt extends React.Component { this.onUrlChanged((e.target as HTMLInputElement).value)} /> + onInput={(e) => this.onUrlChanged((e.target as HTMLInputElement).value)} + onChange={(e) => this.onUrlChanged((e.target as HTMLInputElement).value)} />
+ {this.errorMessage()}
@@ -149,15 +152,12 @@ class ManualSelection extends ImplicitStateComponent { console.log("getExchangeInfo returned"); this.isOkay(true); } catch (e) { - console.log("got error", e); - if (e.hasOwnProperty("httpStatus")) { - this.errorMessage(`Error: request failed with status ${e.httpStatus}`); - } else if (e.hasOwnProperty("errorResponse")) { - const resp = e.errorResponse; - this.errorMessage(`Error: ${resp.error} (${resp.hint})`); - } else { - this.errorMessage("invalid exchange URL"); + if (!(e instanceof WalletApiError)) { + // maybe it's something more serious, don't handle here! + throw e; } + console.log(`got error "${e.message} "with detail`, e.detail); + this.errorMessage(i18n.str`Invalid exchange URL (${e.message})`); } } @@ -345,7 +345,7 @@ class ExchangeSelection extends ImplicitStateComponent {

Known Exchanges

{exchanges.map((e) => ( - ))} @@ -503,7 +503,7 @@ async function main() { // TODO: provide more context information, maybe factor it out into a // TODO:generic error reporting function or component. document.body.innerText = i18n.str`Fatal error: "${e.message}".`; - console.error(`got error "${e.message}"`, e); + console.error("got error", e); } } diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index ee1ca23ba..32788d37b 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -86,7 +86,7 @@ async function callBackend( return new Promise((resolve, reject) => { chrome.runtime.sendMessage({ type, detail }, (resp) => { if (typeof resp === "object" && resp && resp.error) { - const e = new WalletApiError(resp.error.message, resp); + const e = new WalletApiError(resp.message, resp); reject(e); } else { resolve(resp);