Skip to content

Commit

Permalink
Handle body being None
Browse files Browse the repository at this point in the history
  • Loading branch information
hmstepanek committed Dec 14, 2023
1 parent 34fff33 commit a7178d5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions newrelic/hooks/mlmodel_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def wrap_chat_completion_sync(wrapped, instance, args, kwargs):
# There appears to be a bug here in openai v1 where despite having code,
# param, etc in the error response, they are not populated on the exception
# object so grab them from the response body object instead.
body = getattr(exc, "body", {})
body = getattr(exc, "body", {}) or {}
notice_error_attributes = {
"http.statusCode": getattr(exc, "status_code", "") or "",
"error.message": body.get("message", "") or "",
Expand Down Expand Up @@ -638,7 +638,7 @@ async def wrap_chat_completion_async(wrapped, instance, args, kwargs):
# There appears to be a bug here in openai v1 where despite having code,
# param, etc in the error response, they are not populated on the exception
# object so grab them from the response body object instead.
body = getattr(exc, "body", {})
body = getattr(exc, "body", {}) or {}
notice_error_attributes = {
"http.statusCode": getattr(exc, "status_code", "") or "",
"error.message": body.get("message", "") or "",
Expand Down

0 comments on commit a7178d5

Please sign in to comment.