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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

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.

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
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