From dd2efc3d78f2dfda44f8182f9638723dcb839781 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 20 Jul 2020 17:46:49 +0530 Subject: nicer HTTP helper in preparation for better error handling --- src/operations/errors.ts | 58 ------------------------------------------------ 1 file changed, 58 deletions(-) (limited to 'src/operations/errors.ts') 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 @@ -53,64 +53,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( - resp: HttpResponse, - codec: Codec, -): Promise { - // 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. -- cgit v1.2.3