summaryrefslogtreecommitdiff
path: root/lib/open_ai.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/open_ai.ex')
-rw-r--r--lib/open_ai.ex10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/open_ai.ex b/lib/open_ai.ex
index 9feb9a4..e28a610 100644
--- a/lib/open_ai.ex
+++ b/lib/open_ai.ex
@@ -11,6 +11,16 @@ defmodule OpenAi do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} <- HTTPoison.post(url, json, headers, options),
{: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}")}
+ {:error, %HTTPoison.Error{reason: reason}} -> {:error, reason}
+ error -> error
end
end