HttpException.java

  1. package gov.usgs.earthquake.aws;

  2. /**
  3.  * Utility exception class if there are errors while processing an HttpResponse.
  4.  *
  5.  * Formats as string with response code, response message, and response body.
  6.  */
  7. class HttpException extends Exception {
  8.   private static final long serialVersionUID = 1L;

  9.   public final HttpResponse response;

  10.   public HttpException(final HttpResponse response, final String message) {
  11.     super(message);
  12.     this.response = response;
  13.   }

  14.   public String toString() {
  15.     int code;
  16.     String message;
  17.     try {
  18.       code = this.response.connection.getResponseCode();
  19.       message = this.response.connection.getResponseMessage();
  20.     } catch (Exception e) {
  21.       code = -1;
  22.       message = null;
  23.     }
  24.     return this.getMessage()
  25.         + ", response " + code + " " + message
  26.         + " : " + new String(this.response.response);
  27.   }
  28. }