Mocking GenServer authenticate/0

I have a module that calls external API. I mocked it’s calls using Mox. But one function, authenticate takes 0 parameters and fetches username, password and site ID from config module. This function can return {:error | :ok, token}

A session manager gen server is started which on init calls authenticate and on fetch_token returns that state - token.

Current mocking for session manager is this:

  if Mix.env() == :test do
    defp authenticate, do: {:ok, "token"}

Now what happened is that the external API stopped authenticating, maintenance. It returned error which crashed the gen server. I fixed this with catch exit in fetch_token function.

And now I’m wondering is there a way to make a test for this. When the gen server crashed it caused the page where data from external API was used to crash also. So the catch and one extra case handle fixed it but now external API works and I can’t reproduce the same scenario. I would like to have a test of proof that if the same issue occurs it will not be a problem.