How can I Simulate OpenAI being down?

I’m using deno and the package openai to create an OpenAI object as such:

const myOpenAI = new OpenAI();

After this, I use multiple services of openAI, that of course, fail ungracefully when OpenAI is down.
I want to catch failures on the API in order to gracefully do stuff around OpenAI.

The problem:
I’ve managed to produce try/catch statements around my code. The problem is: How can I test them?

Is there an easy way to simulate, OpenAI being down?

Possible solutions: I’ve tried

  • Creating a function that just throws the error: works but diverts the flow of the code, and doesn’t test my function call

  • Producing typos on the openAI call: which seem to instead of throwing errors, produce failures on the build before even running that code.

  • Instead of passing the openAI response, producing undefined or {}: Big no-no, this breaks my typescript :,(

    Anyone has tried another approach that is slick and could be useful?