diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-07-20 17:46:49 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-07-20 17:46:49 +0530 |
commit | dd2efc3d78f2dfda44f8182f9638723dcb839781 (patch) | |
tree | 9cfbd31607f044fb80da80d8f740ae5eaa21a2f4 /src/operations/errors.ts | |
parent | 5a8931d90320ebc8454969ea133c48b6998ad60a (diff) | |
download | wallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.tar.gz wallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.tar.bz2 wallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.zip |
nicer HTTP helper in preparation for better error handling
Diffstat (limited to 'src/operations/errors.ts')
-rw-r--r-- | src/operations/errors.ts | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/src/operations/errors.ts b/src/operations/errors.ts index c8885c9e7..9def02b0e 100644 --- a/src/operations/errors.ts +++ b/src/operations/errors.ts @@ -54,64 +54,6 @@ export class OperationFailedError extends Error { } /** - * Process an HTTP response that we expect to contain Taler-specific JSON. - * - * Depending on the status code, we throw an exception. This function - * will try to extract Taler-specific error information from the HTTP response - * if possible. - */ -export async function scrutinizeTalerJsonResponse<T>( - resp: HttpResponse, - codec: Codec<T>, -): Promise<T> { - // FIXME: We should distinguish between different types of error status - // to react differently (throttle, report permanent failure) - - // FIXME: Make sure that when we receive an error message, - // it looks like a Taler error message - - if (resp.status !== 200) { - let exc: OperationFailedError | undefined = undefined; - try { - const errorJson = await resp.json(); - const m = `received error response (status ${resp.status})`; - exc = new OperationFailedError({ - type: "protocol", - message: m, - details: { - httpStatusCode: resp.status, - errorResponse: errorJson, - }, - }); - } catch (e) { - const m = "could not parse response JSON"; - exc = new OperationFailedError({ - type: "network", - message: m, - details: { - status: resp.status, - }, - }); - } - throw exc; - } - let json: any; - try { - json = await resp.json(); - } catch (e) { - const m = "could not parse response JSON"; - throw new OperationFailedError({ - type: "network", - message: m, - details: { - status: resp.status, - }, - }); - } - return codec.decode(json); -} - -/** * Run an operation and call the onOpError callback * when there was an exception or operation error that must be reported. * The cause will be re-thrown to the caller. |