| 446 | } |
| 447 | |
| 448 | async function handleWebhookError(response: Response, errorType: string) { |
| 449 | const rawErrorBody = await response.json(); |
| 450 | |
| 451 | const parsedErrorBody = AirtableErrorBodySchema.safeParse(rawErrorBody); |
| 452 | |
| 453 | if (!parsedErrorBody.success) { |
| 454 | throw new AirtableSDK.Error( |
| 455 | `${errorType}_PARSE_ERROR`, |
| 456 | `${response.statusText}:\n${rawErrorBody}`, |
| 457 | response.status |
| 458 | ); |
| 459 | } |
| 460 | |
| 461 | const { type, message } = parsedErrorBody.data; |
| 462 | |
| 463 | throw new AirtableSDK.Error(type, message ?? response.statusText, response.status); |
| 464 | } |