getStreamErrorCode.ts 649 B

12345678910111213
  1. import { StreamErrorCode } from '../../interfaces/message-error';
  2. const OpenaiStreamErrorMessageRegExp = {
  3. BUDGET_EXCEEDED: /exceeded your current quota/i, // stream-error-message: "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors."
  4. } as const;
  5. export const getStreamErrorCode = (errorMessage: string): StreamErrorCode | undefined => {
  6. for (const [code, regExp] of Object.entries(OpenaiStreamErrorMessageRegExp)) {
  7. if (regExp.test(errorMessage)) {
  8. return StreamErrorCode[code];
  9. }
  10. }
  11. };