Skip to content

Fix anthropic client to handle nil response

Patrick Bajao requested to merge pb-fix-anthropic-client-server-error into master

What does this MR do and why?

Gitlab::Llm::Anthropic::Client#messages_complete gets the text from JSON response. If server responds with an error though, the response can be nil so calling dig('content', 0, 'text') on it will fail and error out with:

undefined method `dig' for nil:NilClass

To fix this, we use a safe navigation operator so method will return nil instead of erroring out.

This currently affects Duo Code Review as it'll fail to publish a review due to error being raised.

Related discussion on slack (internal) and log (internal).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bajao

Merge request reports

Loading