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,