1 // Copyright 2007 The Android Open Source Project 2 3 package com.google.wireless.gdata2.client; 4 5 import com.google.wireless.gdata2.GDataException; 6 7 import java.io.InputStream; 8 9 /** 10 * A class representing exceptional (i.e., non 200) responses from an HTTP 11 * Server. 12 */ 13 public class HttpException extends GDataException { 14 15 public static final int SC_NOT_MODIFIED = 304; 16 17 public static final int SC_BAD_REQUEST = 400; 18 19 public static final int SC_UNAUTHORIZED = 401; 20 21 public static final int SC_FORBIDDEN = 403; 22 23 public static final int SC_NOT_FOUND = 404; 24 25 public static final int SC_CONFLICT = 409; 26 27 public static final int SC_GONE = 410; 28 29 public static final int SC_PRECONDITION_FAILED = 412; 30 31 public static final int SC_INTERNAL_SERVER_ERROR = 500; 32 33 private final int statusCode; 34 35 private final InputStream responseStream; 36 37 /** 38 * Creates an HttpException with the given message, statusCode and 39 * responseStream. 40 */ HttpException(String message, int statusCode, InputStream responseStream)41 public HttpException(String message, int statusCode, 42 InputStream responseStream) { 43 super(message); 44 this.statusCode = statusCode; 45 this.responseStream = responseStream; 46 } 47 48 /** 49 * Gets the status code associated with this exception. 50 * @return the status code returned by the server, typically one of the SC_* 51 * constants. 52 */ getStatusCode()53 public int getStatusCode() { 54 return statusCode; 55 } 56 57 /** 58 * @return the error response stream from the server. 59 */ getResponseStream()60 public InputStream getResponseStream() { 61 return responseStream; 62 } 63 } 64