Skip to content

Commit

Permalink
fix(api-client): parsing error message when API cannot be reached (#1931
Browse files Browse the repository at this point in the history
)

* fix(api-client): parsing error message when API cannot be reached

* test: add coverage
  • Loading branch information
patzick committed Aug 9, 2022
1 parent ed638ba commit 59da884
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/shopware-6-client/__tests__/apiInterceptors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,16 @@ describe("apiInterceptors", () => {
});
}
});

it("it should not fail when api is unreachable", async () => {
try {
await errorInterceptor({} as any);
} catch (error) {
expect(error).toStrictEqual({
statusCode: 500,
messages: [],
});
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const guessTheStatusCodeFromTheMessage = (message: string): number => {
* @returns {(string|ShopwareError[])} single message if statusCode !== 400, array of native errors otherwise
*/
const extractApiErrorMessage = (error: ShopwareApiError): ShopwareError[] => {
return error.response.data?.errors || [];
return error.response?.data?.errors || [];
};

/**
Expand Down

0 comments on commit 59da884

Please sign in to comment.