summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhref <href@random.sh>2022-12-11 00:27:21 +0000
committerJordan Bracco <href@random.sh>2022-12-11 02:03:36 +0000
commitbefb967563736abe6d3a3365cc3194f47cd04216 (patch)
tree9c60c2b5dc5fede1868eaa4431eea3311f7aedb5
parentcouch: improve, add post, put (diff)
open_ai: improve error handling
Diffstat (limited to '')
-rw-r--r--lib/open_ai.ex9
1 files changed, 1 insertions, 8 deletions
diff --git a/lib/open_ai.ex b/lib/open_ai.ex
index e28a610..81f12f4 100644
--- a/lib/open_ai.ex
+++ b/lib/open_ai.ex
@@ -12,15 +12,8 @@ defmodule OpenAi do
{:ok, data} <- Poison.decode(body) do
{:ok, data}
else
- {:ok, %HTTPoison.Response{status_code: 400}} -> {:error, :bad_request}
- {:ok, %HTTPoison.Response{status_code: 402}} -> {:error, :payment_required}
- {:ok, %HTTPoison.Response{status_code: 403}} -> {:error, :forbidden}
- {:ok, %HTTPoison.Response{status_code: 429}} -> {:error, :too_many_requests}
- {:ok, %HTTPoison.Response{status_code: 500}} -> {:error, :internal_error}
- {:ok, %HTTPoison.Response{status_code: 503}} -> {:error, :service_unavailable}
- {:ok, %HTTPoison.Response{status_code: code}} -> {:error, String.to_atom("http #{code}")}
+ {:ok, %HTTPoison.Response{status_code: code}} -> {:error, Plug.Conn.Status.reason_atom(code)}
{:error, %HTTPoison.Error{reason: reason}} -> {:error, reason}
- error -> error
end
end