Skip to content

Commit

Permalink
simplify error response
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Nov 24, 2023
1 parent 5dc8c2f commit d3daf4e
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions lib/inngest/response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,10 @@ defmodule Inngest.SdkResponse do
end
end

# No retry error response
def from_result({:error, error}, [{:retry, false} | _] = opts) do
stacktrace = Keyword.get(opts, :stacktrace, [])

encoded =
case Exception.format(:error, error, stacktrace) |> Jason.encode() do
{:ok, encoded} -> encoded
{:error, _} -> "Failed to encode error: #{error}"
end

%__MODULE__{
status: 400,
body: encoded,
retry: false
}
end

def from_result({:error, error}, opts) do
stacktrace = Keyword.get(opts, :stacktrace, [])
retry = Keyword.get(opts, :retry, true)
status = if retry, do: 500, else: 400

encoded =
case Exception.format(:error, error, stacktrace) |> Jason.encode() do
Expand All @@ -82,7 +66,7 @@ defmodule Inngest.SdkResponse do
end

%__MODULE__{
status: 500,
status: status,
body: encoded,
retry: retry
}
Expand Down

0 comments on commit d3daf4e

Please sign in to comment.