Skip to content

Commit 19fc3cb

Browse files
committed
Hotfix: More resilient handling of API exceptions
1 parent e73019b commit 19fc3cb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/jobs/get_next_ai_message_job.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ def perform(user_id, message_id, assistant_id, attempt = 1)
103103
GetNextAIMessageJob.broadcast_updated_message(@message, thinking: false)
104104
GetNextAIMessageJob.set(wait: (attempt+1).seconds).perform_later(user_id, message_id, assistant_id, attempt+1)
105105
else
106-
error_text = nil
107-
begin
108-
error_text = e&.response&.dig(:body, "error", "message") rescue e&.response&.dig(:body)
106+
error_text = if e.try(:response)
107+
e&.response&.dig(:body, "error", "message") rescue e&.response&.dig(:body)
108+
else
109+
e.message
109110
end
110111
set_unexpected_error(msg&.slice(0...1500), error_text)
111112
wrap_up_the_message

0 commit comments

Comments
 (0)