Nil respose body results in error when logging

One this line of code we run parsed_response.dig('detail', 0, 'msg') on the JSON parsed response body from a Chat request.

But if the response body is nil, we get the following error:

TypeError String does not have #dig method ["/Users/jessieyoung/gdk-new/gitlab/ee/lib/gitlab/llm/ai_gateway/client.rb:55:in `dig'",

I saw this in my GDK when receiving a 404:

http_exception_details=404: Not Found http_version=1.1 method=POST path=/ai/v1/chat/agent status_code=404 url=http://0.0.0.0:5052/ai/v1/chat/agent user_agent=Ruby

To handle cases where a 4xx error is returned from the AI Gateway, we should gracefully handle this situation.

Edited by 🤖 GitLab Bot 🤖