Skip to content

Commit

Permalink
[SDK] network error leads to unwanted behavior (#202)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* fix: add error message on all places and only show path

---------

Co-authored-by: Julian König <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent f3a219d commit d29559a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/sdk/src/endpoints/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d29559a

Please sign in to comment.