Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1106)

Side by Side Diff: components/cronet/android/api/src/org/chromium/net/UrlRequestException.java

Issue 1393713005: [Cronet] Add error code and immediatelyRetryable() to UrlRequestException (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix missing test annotation Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import java.io.IOException; 7 import java.io.IOException;
8 8
9 /** 9 /**
10 * Exception after UrlRequest start. Could be reported by network stack, in 10 * Exception passed to {@link UrlRequest.Callback#onFailed UrlRequest.Callback.o nFailed()} when:
11 * which case netError() will contain native error code. 11 * <ul>
12 * <li>{@link UrlRequest.Callback} or {@link UploadDataProvider} method throws a n exception. In this
13 * case {@link IOException#getCause getCause()} can be used to find the thro wn exception.
14 * {@link #getErrorCode} will return {@link #ERROR_LISTENER_EXCEPTION_THROWN }.
15 * <li>Cronet fails to process a network request. In this case
16 * {@link #getErrorCode} and {@link #getCronetInternalErrorCode} can be used to get more
17 * information about the specific type of failure.
18 * </ul>
12 */ 19 */
13 public class UrlRequestException extends IOException { 20 public class UrlRequestException extends IOException {
14 /** Net error code if exception is reported by native. */ 21 /**
15 final int mNetError; 22 * Error code indicating this class wraps an exception thrown by {@link UrlR equest.Callback} or
23 * {@link UploadDataProvider}. Wrapped exception can be retrieved using
24 * {@link IOException#getCause}.
25 */
26 public static final int ERROR_LISTENER_EXCEPTION_THROWN =
27 UrlRequestError.LISTENER_EXCEPTION_THROWN;
28 /**
29 * Error code indicating the host being sent the request could not be resolv ed to an IP address.
30 */
31 public static final int ERROR_HOSTNAME_NOT_RESOLVED = UrlRequestError.HOSTNA ME_NOT_RESOLVED;
32 /**
33 * Error code indicating the device was not connected to any network.
34 */
35 public static final int ERROR_INTERNET_DISCONNECTED = UrlRequestError.INTERN ET_DISCONNECTED;
36 /**
37 * Error code indicating that as the request was processed the network confi guration changed.
38 */
39 public static final int ERROR_NETWORK_CHANGED = UrlRequestError.NETWORK_CHAN GED;
40 /**
41 * Error code indicating a timeout expired. Timeouts expiring while attempti ng to connect will
42 * be reported as the more specific {@link #ERROR_CONNECTION_TIMED_OUT}.
43 */
44 public static final int ERROR_TIMED_OUT = UrlRequestError.TIMED_OUT;
45 /**
46 * Error code indicating the connection was closed unexpectedly.
47 */
48 public static final int ERROR_CONNECTION_CLOSED = UrlRequestError.CONNECTION _CLOSED;
49 /**
50 * Error code indicating the connection attempt timed out.
51 */
52 public static final int ERROR_CONNECTION_TIMED_OUT = UrlRequestError.CONNECT ION_TIMED_OUT;
53 /**
54 * Error code indicating the connection attempt was refused.
55 */
56 public static final int ERROR_CONNECTION_REFUSED = UrlRequestError.CONNECTIO N_REFUSED;
57 /**
58 * Error code indicating the connection was unexpectedly reset.
59 */
60 public static final int ERROR_CONNECTION_RESET = UrlRequestError.CONNECTION_ RESET;
61 /**
62 * Error code indicating the IP address being contacted is unreachable, mean ing there is no
63 * route to the specified host or network.
64 */
65 public static final int ERROR_ADDRESS_UNREACHABLE = UrlRequestError.ADDRESS_ UNREACHABLE;
66 /**
67 * Error code indicating another type of error was encountered.
68 * {@link #getCronetInternalErrorCode} can be consulted to get a more specif ic cause.
69 */
70 public static final int ERROR_OTHER = UrlRequestError.OTHER;
16 71
17 UrlRequestException(String message, Throwable cause) { 72 // Error code, one of ERROR_*
18 super(message, cause); 73 private final int mErrorCode;
19 mNetError = 0; 74 // Cronet internal error code.
75 private final int mCronetInternalErrorCode;
76
77 /**
78 * Constructs an exception with a specific error.
79 *
80 * @param message explanation of failure.
81 * @param errorCode error code, one of {@link #ERROR_LISTENER_EXCEPTION_THRO WN ERROR_*}.
82 * @param cronetInternalErrorCode Cronet internal error code, one of
83 * <a href=https://chromium.googlesource.com/chromium/src/+/master/net/base/ net_error_list.h>
84 * these</a>.
85 */
86 public UrlRequestException(String message, int errorCode, int cronetInternal ErrorCode) {
87 super(message, null);
88 mErrorCode = errorCode;
89 mCronetInternalErrorCode = cronetInternalErrorCode;
20 } 90 }
21 91
22 UrlRequestException(String message, int netError) { 92 /**
23 super(message, null); 93 * Constructs an exception that wraps {@code cause} thrown by a {@link UrlRe quest.Callback}.
24 mNetError = netError; 94 *
95 * @param message explanation of failure.
96 * @param cause exception thrown by {@link UrlRequest.Callback} that's being wrapped.
97 */
98 public UrlRequestException(String message, Throwable cause) {
99 super(message, cause);
100 mErrorCode = ERROR_LISTENER_EXCEPTION_THROWN;
101 mCronetInternalErrorCode = 0;
25 } 102 }
26 103
27 /** @return Error code if exception is reported by native. */ 104 /**
28 public int netError() { 105 * Returns error code, one of {@link #ERROR_LISTENER_EXCEPTION_THROWN ERROR_ *}.
29 return mNetError; 106 *
107 * @return error code, one of {@link #ERROR_LISTENER_EXCEPTION_THROWN ERROR_ *}.
108 */
109 public int getErrorCode() {
110 return mErrorCode;
111 }
112
113 /**
114 * Returns a Cronet internal error code. This may provide more specific erro r
115 * diagnosis than {@link #getErrorCode}, but the constant values are not exp osed to Java and
116 * may change over time. See
117 * <a href=https://chromium.googlesource.com/chromium/src/+/master/net/base/ net_error_list.h>
118 * here</a> for the lastest list of values.
119 *
120 * @return Cronet internal error code.
121 */
122 public int getCronetInternalErrorCode() {
123 return mCronetInternalErrorCode;
124 }
125
126 /**
127 * Returns {@code true} if retrying this request right away might succeed, { @code false}
128 * otherwise. For example returns {@code true} when {@link #getErrorCode} re turns
129 * {@link #ERROR_NETWORK_CHANGED} because trying the request might succeed u sing the new
130 * network configuration, but {@code false} when {@code getErrorCode()} retu rns
131 * {@link #ERROR_INTERNET_DISCONNECTED} because retrying the request right a way will
132 * encounter the same failure (instead retrying should be delayed until devi ce regains
133 * network connectivity). Returns {@code false} when {@code getErrorCode()} returns
134 * {@link #ERROR_LISTENER_EXCEPTION_THROWN}.
135 *
136 * @return {@code true} if retrying this request right away might succeed, { @code false}
137 * otherwise.
138 */
139 public boolean immediatelyRetryable() {
140 switch (mErrorCode) {
141 case ERROR_LISTENER_EXCEPTION_THROWN:
142 case ERROR_HOSTNAME_NOT_RESOLVED:
143 case ERROR_INTERNET_DISCONNECTED:
144 case ERROR_CONNECTION_REFUSED:
145 case ERROR_ADDRESS_UNREACHABLE:
146 case ERROR_OTHER:
147 default:
148 return false;
149 case ERROR_NETWORK_CHANGED:
150 case ERROR_TIMED_OUT:
151 case ERROR_CONNECTION_CLOSED:
152 case ERROR_CONNECTION_TIMED_OUT:
153 case ERROR_CONNECTION_RESET:
154 return true;
155 }
30 } 156 }
31 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698