getStreamErrorCode.ts 654 B

123456789101112131415
  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 = (
  6. errorMessage: string,
  7. ): StreamErrorCode | undefined => {
  8. for (const [code, regExp] of Object.entries(OpenaiStreamErrorMessageRegExp)) {
  9. if (regExp.test(errorMessage)) {
  10. return StreamErrorCode[code];
  11. }
  12. }
  13. };