From d29559acd1e9aa1b0d8388c5cfcd495ccb8284aa Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Wed, 3 Jul 2024 15:08:53 +0200 Subject: [PATCH] [SDK] network error leads to unwanted behavior (#202) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: sdk error message on network error was showing not all details * Update packages/sdk/src/endpoints/Endpoint.ts Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com> * fix: add error message on all places and only show path --------- Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- packages/sdk/src/endpoints/Endpoint.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/sdk/src/endpoints/Endpoint.ts b/packages/sdk/src/endpoints/Endpoint.ts index d639d49f..4e5876bb 100644 --- a/packages/sdk/src/endpoints/Endpoint.ts +++ b/packages/sdk/src/endpoints/Endpoint.ts @@ -47,7 +47,11 @@ export abstract class Endpoint { if (httpResponse.status !== expectedStatus) { const errorPayload = httpResponse.data.error; - + if (!errorPayload) { + throw new Error( + `The http request to connector route '${httpResponse.request.path}' failed with status '${httpResponse.status}': ${httpResponse.statusText} ${httpResponse.data}` + ); + } return ConnectorResponse.error({ id: errorPayload.id, docs: errorPayload.docs, @@ -69,6 +73,12 @@ export abstract class Endpoint { // Manually parse data because responseType is "arrayBuffer" const errorPayload = JSON.parse(httpResponse.data).error; + if (!errorPayload) { + throw new Error( + `The http request to connector route '${httpResponse.request.path}' failed with status '${httpResponse.status}': ${httpResponse.statusText} ${httpResponse.data}` + ); + } + return ConnectorResponse.error({ id: errorPayload.id, docs: errorPayload.docs, @@ -104,6 +114,12 @@ export abstract class Endpoint { if (httpResponse.status !== expectedStatus) { const errorPayload = httpResponse.data.error; + if (!errorPayload) { + throw new Error( + `The http request to connector route '${httpResponse.request.path}' failed with status '${httpResponse.status}': ${httpResponse.statusText} ${httpResponse.data}` + ); + } + return ConnectorResponse.error({ id: errorPayload.id, docs: errorPayload.docs,