Error Handling for Node.js Assistants API

Using Assistants API, I ran into an error: “You exceeded your current quota, please check your plan and billing details” that I can see if I go to Threads on the OpenAI website.
How can we handle this error gracefully, get this message to be able to display it to the UI?
Relevant code:

  const createdMessage = await openai.beta.threads.messages.create(threadId, {
    role: "user",
    content: input.message,
  });

  const runStream = openai.beta.threads.runs.stream(threadId, { assistant_id });
let runResult = await forwardStream(runStream);

      const responseMessages = (
        await openai.beta.threads.messages.list(threadId, {
          order: "asc",
        })
      ).data;
1 Like