summaryrefslogtreecommitdiff
path: root/src/com/google/wireless/gdata/client/HttpException.java
blob: 48f10330625e57616307a43972c8f3f0f02718bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2007 The Android Open Source Project

package com.google.wireless.gdata.client;

import java.io.InputStream;

/**
 * A class representing exceptional (i.e., non 200) responses from an HTTP
 * Server.
 */
public class HttpException extends Exception {

  public static final int SC_BAD_REQUEST = 400;

  public static final int SC_UNAUTHORIZED = 401;

  public static final int SC_FORBIDDEN = 403;

  public static final int SC_NOT_FOUND = 404;

  public static final int SC_CONFLICT = 409;

  public static final int SC_GONE = 410;

  public static final int SC_INTERNAL_SERVER_ERROR = 500;

  private final int statusCode;

  private final InputStream responseStream;

  /**
   * Creates an HttpException with the given message, statusCode and
   * responseStream.
   */
  //TODO: also record response headers?
  public HttpException(String message, int statusCode,
      InputStream responseStream) {
    super(message);
    this.statusCode = statusCode;
    this.responseStream = responseStream;
  }

  /**
   * Gets the status code associated with this exception.
   * @return the status code returned by the server, typically one of the SC_*
   * constants.
   */
  public int getStatusCode() {
    return statusCode;
  }

  /**
   * @return the error response stream from the server.
   */
  public InputStream getResponseStream() {
    return responseStream;
  }
}