diff --git a/packages/platform-sdk/test/integration-tests/sdk-v3/error-cases.test.ts b/packages/platform-sdk/test/integration-tests/sdk-v3/error-cases.test.ts new file mode 100644 index 000000000..4d4eab984 --- /dev/null +++ b/packages/platform-sdk/test/integration-tests/sdk-v3/error-cases.test.ts @@ -0,0 +1,17 @@ +import { apiRootV3 } from '../test-utils' + +describe('testing error cases', () => { + it('should throw error when a product type is not found', async () => { + try { + await apiRootV3 + .productTypes() + .withId({ ID: 'non-existing-id' }) + .get() + .execute() + + throw new Error('Should have thrown an error') + } catch (e) { + expect(e.statusCode).toEqual(404) + } + }) +}) diff --git a/packages/sdk-client-v3/src/client/client.ts b/packages/sdk-client-v3/src/client/client.ts index 9f4617205..0281232ca 100644 --- a/packages/sdk-client-v3/src/client/client.ts +++ b/packages/sdk-client-v3/src/client/client.ts @@ -176,7 +176,13 @@ export default function createClient(middlewares: ClientOptions): Client { resolve, ...request, }) - .then(resolve) + .then((res) => { + if (res.error) { + reject(res.error) + } else { + resolve(res) + } + }) .catch(reject) }) },