Builder class for constructing a {@link ResponseFuture} that represents a failed request.We can use this builder to create {@link ResponseFuture}s representing one of two kinds of failed requests:
- No information was returned by the server. A {@link ResponseFuture} representing this case can be built usingthe {@link #setErrorResponse(com.linkedin.restli.common.ErrorResponse)} method.
- The server returned partial results. A {@link ResponseFuture} representing this case can be built using the{@link #setEntity(com.linkedin.data.template.RecordTemplate)} method.
In the documentation below the phrase " {@link ResponseFuture} accessor methods" refers to{@link com.linkedin.restli.client.ResponseFuture#getResponse()}, {@link ResponseFuture#getResponse(long,java.util.concurrent.TimeUnit)}, {@link com.linkedin.restli.client.ResponseFuture#getResponseEntity()}, or {@link ResponseFuture#getResponseEntity(long,java.util.concurrent.TimeUnit)}.
If we are trying to represent the case where no information was returned from the server (i.e case (1) above):
- if {@link ErrorHandlingBehavior#FAIL_ON_ERROR} is being used then a {@link RestLiResponseException} is thrownwhen any {@link ResponseFuture} accessor method is called. The {@link ErrorResponse}used to construct the {@link ResponseFuture} is used to populate this {@link RestLiResponseException}.
- if {@link ErrorHandlingBehavior#TREAT_SERVER_ERROR_AS_SUCCESS} is being used then noexception is thrown when one of the {@link ResponseFuture} accessor methods is called. Instead, a{@link Response} is returned which returns a {@link RestLiResponseException} constructed fromthe {@link ErrorResponse} when {@link com.linkedin.restli.client.Response#getError()} is called. The returned{@link Response} has a {@code null} entity.
If we are trying to represent the case where the server returns partial results (i.e. case (2) above):
- if {@link ErrorHandlingBehavior#FAIL_ON_ERROR} is being used then a {@link RestLiResponseException} is thrownwhen any {@link ResponseFuture} accessor method is called. Calling{@link com.linkedin.restli.client.RestLiResponseException#getDecodedResponse()} on this exception will returna {@link Response} that has its entity as the object that was used in{@link #setEntity(com.linkedin.data.template.RecordTemplate)}. The other fields on this {@link Response}correspond to setters invoked in this class. E.g. calling {@link com.linkedin.restli.client.Response#getStatus()}will return the HTTP status code that was set in {@link #setStatus(int)}
- if {@link ErrorHandlingBehavior#TREAT_SERVER_ERROR_AS_SUCCESS} is being used then no exception is thrownand a {@link Response} object is returned that has its that entity as the object that was used in{@link #setEntity(com.linkedin.data.template.RecordTemplate)}. The other fields on this {@link Response}correspond to setters invoked in this class. E.g. calling {@link com.linkedin.restli.client.Response#getStatus()}will return the HTTP status code that was set in {@link #setStatus(int)}
If neither {@link #setEntity(com.linkedin.data.template.RecordTemplate)} or{@link #setErrorResponse(com.linkedin.restli.common.ErrorResponse)} is called, then we assume case (1) is desired.An {@link ErrorResponse} will be constructed in this case using the status set via {@link #setStatus(int)} or{@link #DEFAULT_HTTP_STATUS} if that method was not called.
@author kparikh
@param < K> key type of the mocked response
@param < V> entity type of the mocked response