feat(medusa): remove created reservations on subsequent failure for cart completion (#3554)

**What**
- If cart completion fails after creating reservations, remove those reservations

**Why**
- To avoid hanging reservations if something fails at a later point
This commit is contained in:
Philip Korsholm
2023-03-29 17:03:53 +00:00
committed by GitHub
parent a7e3f2d343
commit 5fd74b38ae
7 changed files with 160 additions and 43 deletions
@@ -4,6 +4,7 @@ export enum PostgresError {
DUPLICATE_ERROR = "23505",
FOREIGN_KEY_ERROR = "23503",
SERIALIZATION_FAILURE = "40001",
NULL_VIOLATION = "23502",
}
export const formatException = (err): MedusaError => {
@@ -43,6 +44,12 @@ export const formatException = (err): MedusaError => {
err?.detail ?? err?.message
)
}
case PostgresError.NULL_VIOLATION: {
return new MedusaError(
MedusaError.Types.INVALID_DATA,
`Can't insert null value in field ${err?.column} on insert in table ${err?.table}`
)
}
default:
return err
}