| 1046 | 1046 | const responseText = await errorResponse.text(); |
| 1047 | 1047 | const errorData = tryParse(responseText); |
| 1048 | 1048 | |
| 1049 | | - const statusMessages = { |
| 1049 | + const message = errorResponse.statusText || 'Unknown error occurred'; |
| 1050 | | - 400: 'Bad request', |
| 1051 | | - 401: 'Unauthorized', |
| 1052 | | - 402: 'Credit limit reached', |
| 1053 | | - 403: 'Forbidden', |
| 1054 | | - 404: 'Not found', |
| 1055 | | - 429: 'Too many requests', |
| 1056 | | - 451: 'Unavailable for legal reasons', |
| 1057 | | - 502: 'Bad gateway', |
| 1058 | | - }; |
| 1059 | | - |
| 1060 | | - const message = errorData?.error?.message || statusMessages[errorResponse.status] || 'Unknown error occurred'; |
| 1061 | 1050 | const quota_error = errorResponse.status === 429 && errorData?.error?.type === 'insufficient_quota'; |
| 1062 | 1051 | console.log(message, responseText); |
| 1063 | 1052 | |
| 1064 | 1053 | if (!response.headersSent) { |
| 1065 | 1054 | response.send({ error: { message }, quota_error: quota_error }); |