diff options
author | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
commit | 5d23eb36354d07508a015531f298b3e261bbafce (patch) | |
tree | fae0d2599c94d88c9264bb63a301adb1706824c1 /packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts | |
parent | f8d12f7b0d4af1b1769b89e80c87f9c169678564 (diff) | |
download | wallet-core-5d23eb36354d07508a015531f298b3e261bbafce.tar.xz |
wallet: improve error handling and error codes
Diffstat (limited to 'packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts b/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts index 6f2585c1e..4dee28a6c 100644 --- a/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts +++ b/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts @@ -23,7 +23,7 @@ import { HttpRequestLibrary, HttpRequestOptions, HttpResponse, - OperationFailedError, + TalerError, } from "@gnu-taler/taler-wallet-core"; /** @@ -44,14 +44,14 @@ export class ServiceWorkerHttpLib implements HttpRequestLibrary { if (this.throttlingEnabled && this.throttle.applyThrottle(requestUrl)) { const parsedUrl = new URL(requestUrl); - throw OperationFailedError.fromCode( + throw TalerError.fromDetail( TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED, - `request to origin ${parsedUrl.origin} was throttled`, { requestMethod, requestUrl, throttleStats: this.throttle.getThrottleStats(requestUrl), }, + `request to origin ${parsedUrl.origin} was throttled`, ); } @@ -107,13 +107,13 @@ function makeTextHandler(response: Response, requestUrl: string) { try { respText = await response.text(); } catch (e) { - throw OperationFailedError.fromCode( + throw TalerError.fromDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, - "Invalid JSON from HTTP response", { requestUrl, httpStatusCode: response.status, }, + "Invalid JSON from HTTP response", ); } return respText; @@ -126,23 +126,23 @@ function makeJsonHandler(response: Response, requestUrl: string) { try { responseJson = await response.json(); } catch (e) { - throw OperationFailedError.fromCode( + throw TalerError.fromDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, - "Invalid JSON from HTTP response", { requestUrl, httpStatusCode: response.status, }, + "Invalid JSON from HTTP response", ); } if (responseJson === null || typeof responseJson !== "object") { - throw OperationFailedError.fromCode( + throw TalerError.fromDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, - "Invalid JSON from HTTP response", { requestUrl, httpStatusCode: response.status, }, + "Invalid JSON from HTTP response", ); } return responseJson; |