| 1 | import type { StripeOpError } from "@distilled.cloud/stripe"; |
| 2 | |
| 3 | /** |
| 4 | * Stripe retrieve/delete often returns `InvalidRequestError` with |
| 5 | * `code: "resource_missing"` instead of a typed NotFound. HTTP 5xx errors |
| 6 | * carry a numeric `code`, so this predicate must accept the full |
| 7 | * {@link StripeOpError} union (not `{ code?: string }`). |
| 8 | */ |
| 9 | export const isMissingStripeResource = (error: StripeOpError): boolean => { |
| 10 | if (error._tag === "NotFound") { |
| 11 | return true; |
| 12 | } |
| 13 | return ( |
| 14 | error._tag === "InvalidRequestError" && error.code === "resource_missing" |
| 15 | ); |
| 16 | }; |