From c88f2454f1cedb497131e6f1fa4429bd3a38185f Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Fri, 9 Dec 2022 17:33:00 +0000 Subject: gpt improvements --- lib/open_ai.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/open_ai.ex') 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 -- cgit v1.2.3