feat: Normalize known DB errors to a MedusaError when possible (#6922)

Before we would swallow the error and return a generic error to the user. This will provide more information to the caller if it is one of the known errors.
This commit is contained in:
Stevche Radevski
2024-04-04 19:12:59 +00:00
committed by GitHub
parent e944a627f0
commit 20e8df914e
14 changed files with 282 additions and 169 deletions
@@ -512,7 +512,7 @@ moduleIntegrationTestRunner({
const err = await service.create(data).catch((e) => e)
expect(err).toBeDefined()
expect(err.constraint).toBe("IDX_fulfillment_set_name_unique")
expect(err.message).toContain("exists")
})
it("should fail on creating a new fulfillment set with new service zones and new geo zones that are not valid", async function () {
@@ -837,7 +837,7 @@ moduleIntegrationTestRunner({
const err = await service.update(updateData).catch((e) => e)
expect(err).toBeDefined()
expect(err.constraint).toBe("IDX_fulfillment_set_name_unique")
expect(err.message).toContain("exists")
})
it("should update a collection of fulfillment sets and replace old service zones by new ones", async function () {
@@ -187,7 +187,7 @@ moduleIntegrationTestRunner({
const err = await service.createServiceZones(data).catch((e) => e)
expect(err).toBeDefined()
expect(err.constraint).toBe("IDX_service_zone_name_unique")
expect(err.message).toContain("exists")
})
it("should fail on creating a service zone and new geo zones that are not valid", async function () {
@@ -435,7 +435,7 @@ moduleIntegrationTestRunner({
.catch((e) => e)
expect(err).toBeDefined()
expect(err.constraint).toBe("IDX_service_zone_name_unique")
expect(err.message).toContain("exists")
})
})
})
@@ -73,7 +73,7 @@ moduleIntegrationTestRunner({
.catch((e) => e)
expect(err).toBeDefined()
expect(err.constraint).toBe("IDX_shipping_profile_name_unique")
expect(err.message).toContain("exists")
})
})
})