Skip to content

Commit 21e04a6

Browse files
authored
fix(647): fix error not thrown (#678)
1 parent 8d2df4d commit 21e04a6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { apiRootV3 } from '../test-utils'
2+
3+
describe('testing error cases', () => {
4+
it('should throw error when a product type is not found', async () => {
5+
try {
6+
await apiRootV3
7+
.productTypes()
8+
.withId({ ID: 'non-existing-id' })
9+
.get()
10+
.execute()
11+
12+
throw new Error('Should have thrown an error')
13+
} catch (e) {
14+
expect(e.statusCode).toEqual(404)
15+
}
16+
})
17+
})

packages/sdk-client-v3/src/client/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ export default function createClient(middlewares: ClientOptions): Client {
176176
resolve,
177177
...request,
178178
})
179-
.then(resolve)
179+
.then((res) => {
180+
if (res.error) {
181+
reject(res.error)
182+
} else {
183+
resolve(res)
184+
}
185+
})
180186
.catch(reject)
181187
})
182188
},

0 commit comments

Comments
 (0)