View Javadoc

1   package com.atlassian.httpclient.api;
2   
3   /**
4    * Thrown to indicate that a response completed normally but that produced an
5    * unexpected status code.
6    */
7   public class UnexpectedResponseException extends RuntimeException {
8       private Response response;
9   
10      /**
11       * Creates a new exception for the given response.
12       *
13       * @param response The unexpected response
14       */
15      public UnexpectedResponseException(Response response) {
16          this.response = response;
17      }
18  
19      /**
20       * Returns the unexpected response
21       *
22       * @return The response
23       */
24      public Response getResponse() {
25          return response;
26      }
27  
28      @Override
29      public String toString() {
30          StringBuilder sb = new StringBuilder();
31          sb.append("Unexpected response '").append(response.getStatusCode()).append("' with message '");
32          sb.append(response.getStatusText()).append("'");
33          return sb.toString();
34      }
35  }