Package com.sap.ai.sdk.core.common
Class ClientResponseHandler<T,R extends ClientError,E extends ClientException>
java.lang.Object
com.sap.ai.sdk.core.common.ClientResponseHandler<T,R,E>
- Type Parameters:
T- the type of the successful response.R- the type of the error response.E- the type of the exception to throw.
- All Implemented Interfaces:
org.apache.hc.core5.http.io.HttpClientResponseHandler<T>
- Direct Known Subclasses:
ClientStreamingHandler
public class ClientResponseHandler<T,R extends ClientError,E extends ClientException>
extends Object
implements org.apache.hc.core5.http.io.HttpClientResponseHandler<T>
Parses incoming JSON responses and handles any errors.
For internal use only.
- Since:
- 1.1.0
-
Constructor Summary
ConstructorsConstructorDescriptionClientResponseHandler(Class<T> successType, Class<? extends R> errorType, ClientExceptionFactory<E, R> exceptionFactory) Creates a newClientResponseHandlerinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildAndThrowException(org.apache.hc.core5.http.ClassicHttpResponse httpResponse) For internal SDK usage only.handleResponse(org.apache.hc.core5.http.ClassicHttpResponse response) Internal SDK usage only.objectMapper(com.fasterxml.jackson.databind.ObjectMapper jackson) Internal SDK usage only.protected voidparseErrorResponseAndThrow(String content, org.apache.hc.core5.http.ClassicHttpResponse httpResponse) For internal SDK usage only.
-
Constructor Details
-
ClientResponseHandler
public ClientResponseHandler(@Nonnull Class<T> successType, @Nonnull Class<? extends R> errorType, @Nonnull ClientExceptionFactory<E, R> exceptionFactory) Creates a newClientResponseHandlerinstance.- Parameters:
successType- The HTTP success response type.errorType- The HTTP error response type.exceptionFactory- The factory to create exceptions for Http 4xx/5xx responses.
-
-
Method Details
-
objectMapper
@Nonnull public ClientResponseHandler<T,R, objectMapperE> (@Nonnull com.fasterxml.jackson.databind.ObjectMapper jackson) Internal SDK usage only. Set theObjectMapperto use for parsing JSON responses.- Parameters:
jackson- theObjectMapperto use.- Returns:
- the current instance of
ClientResponseHandlerwith the changed object mapper.
-
handleResponse
@Nonnull public T handleResponse(@Nonnull org.apache.hc.core5.http.ClassicHttpResponse response) throws E Internal SDK usage only. Processes aClassicHttpResponseand returns some value corresponding to that response.- Specified by:
handleResponsein interfaceorg.apache.hc.core5.http.io.HttpClientResponseHandler<T>- Parameters:
response- the response to process.- Returns:
- a model class instantiated from the response.
- Throws:
E- in case of a problem or the connection was aborted.
-
buildAndThrowException
protected void buildAndThrowException(@Nonnull org.apache.hc.core5.http.ClassicHttpResponse httpResponse) throws E For internal SDK usage only. Process the error response and throw an exception.- Parameters:
httpResponse- the response to process.- Throws:
ClientException- if the response is an error (4xx/5xx).E
-
parseErrorResponseAndThrow
protected void parseErrorResponseAndThrow(@Nonnull String content, @Nonnull org.apache.hc.core5.http.ClassicHttpResponse httpResponse) throws E For internal SDK usage only. Parses the JSON content of an error response and throws a module specific exception.- Parameters:
content- the JSON content of the error response.httpResponse- the HTTP response that contains the error.- Throws:
ClientException- if the response is an error (4xx/5xx).E
-