Skip to content

chore: Improve Exception Handling and Accessors to Response/Request #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 13, 2025

Conversation

newtork
Copy link
Contributor

@newtork newtork commented Aug 6, 2025

Context

https://github.com/SAP/ai-sdk-java-backlog/issues/290

Since we removed logging of HTTP request/responses from our code, we want to ease troubleshooting in the future.

Feature scope:

  • Add exception field for HttpResponse (if available)
  • Add exception field for HttpRequest (if available)
  • Ease implementation
    • Factory is now a functional-interface
    • Factory implementations for OpenAI and Orchestration are now method references
    • Ease API contract for exceptions, allow for setting fields with pubic accessor

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Aligned changes with the JavaScript SDK
  • Documentation updated
  • Release notes updated

@@ -102,7 +101,7 @@ public static void send(@Nonnull final ResponseBodyEmitter emitter, @Nonnull fin
try {
emitter.send(chunk);
} catch (final IOException e) {
log.error(Arrays.toString(e.getStackTrace()));
log.error("Failed to send chunk: {}", e.getMessage(), e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor drive-by change.

@newtork newtork added the please-review Request to review a pull-request label Aug 6, 2025
@newtork newtork self-assigned this Aug 7, 2025
Copy link
Member

@rpanackal rpanackal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I really like the functional interface approach.

I just had one question/suggestion.

Otherwise, I would approve.

@Getter(onMethod_ = @Beta, value = AccessLevel.PROTECTED)
@Setter(onMethod_ = @Beta, value = AccessLevel.PROTECTED)
ClientError clientError;
@Getter(onMethod_ = @Beta, value = AccessLevel.PUBLIC)
Copy link
Member

@rpanackal rpanackal Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Question/Suggestion)

Should getClientError() remain protected? As far as I see, ClientError is an internal wrapper for error response.

For users, there exist a getErrorResponse() in module specific exceptions like OpenAiClientException to shortcut access to the error response.

I feel like getErrorResponse() is convenient than getClientError() and would reduce confusion. Having both method public may be redundant?

Copy link
Contributor Author

@newtork newtork Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following API is available

catch(OrchestrationClientException e) {
  e.getMessage(); // default
  e.getCause(); // default

  e.getHttpResponse(); // ClassicHttpResponse
  e.getHttpRequest(); // ClassicHttpRequest
  e.getClientError().getMessage(); // convenient message
  e.getErrorResponse(); // ErrorResponse (model class)
  e.getErrorResponseStreaming(); // ErrorResponseStreaming  (model class)
}

The e.getClientError().getMessage() is the reason.
However I would also prefer if it wasn't split.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string from e.getMessage() contains e.getClientError().getMessage().

We don't need to expose e.getClientError().getMessage() and leave it as simply a method for error response type-agnostic retrieval of message.

No strong opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to expose e.getClientError().getMessage()

I was not planning to challenge visibility of this method in this PR. 🤔

newtork and others added 6 commits August 12, 2025 18:02
…esponse

# Conflicts:
#	docs/release_notes.md
#	orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClientException.java
#	orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationExceptionFactory.java
#	orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java
@newtork newtork merged commit b35d43e into main Aug 13, 2025
7 checks passed
@newtork newtork deleted the exceptions-with-httpresponse branch August 13, 2025 12:12
@newtork newtork mentioned this pull request Aug 13, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please-review Request to review a pull-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants