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

Side by Side Diff: components/cronet/android/java/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: Created 5 years, 2 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 UrlRequestListener#onFailed UrlRequestListener.onF ailed()} when:
11 * which case netError() will contain native error code. 11 * <ul>
12 * <li>{@link UrlRequestListener} or {@link UploadDataProvider} method throws an 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_THREW}.
15 * <li>Cronet fails to process a network request. In this case
16 * {@link #getErrorCode} and {@link #netError} 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 // Error code, one of ERROR_*
15 final int mNetError; 22 private final int mErrorCode;
23 // Cronet error code.
24 private final int mCronetError;
xunjieli 2015/10/13 23:07:10 static variables should go before non-static ones.
pauljensen 2015/11/05 18:35:29 Done.
16 25
17 UrlRequestException(String message, Throwable cause) { 26 /**
27 * Error code indicating this class wraps an exception thrown by {@link UrlR equestListener} or
28 * {@link UploadDataProvider}. Wrapped exception can be retrieved using
29 * {@link IOException#getCause}.
30 */
31 public static final int ERROR_LISTENER_THREW = UrlRequestError.LISTENER_THRE W;
xunjieli 2015/10/13 23:07:10 What about ERROR_LISTENER_EXCEPTION_THROWN? The ot
pauljensen 2015/11/05 18:35:29 I was taught that passive voice is to be avoided w
xunjieli 2015/11/06 15:23:22 Hmm.. my grammar is failing me. I guess this isn't
pauljensen 2016/01/25 02:08:16 Done; I changed it to ERROR_LISTENER_EXCEPTION_THR
32 /**
33 * Error code indicating the host being sent the request could not be resolv ed to an IP address.
34 */
35 public static final int ERROR_HOSTNAME_NOT_RESOLVED = UrlRequestError.HOSTNA ME_NOT_RESOLVED;
36 /**
37 * Error code indicating the device was not connected to any network.
38 */
39 public static final int ERROR_INTERNET_DISCONNECTED = UrlRequestError.INTERN ET_DISCONNECTED;
40 /**
41 * Error code indicating that as the request was processed the network confi guration chnaged.
42 */
43 public static final int ERROR_NETWORK_CHANGED = UrlRequestError.NETWORK_CHAN GED;
44 /**
45 * Error code indicating a timeout expired.
46 */
47 public static final int ERROR_TIMED_OUT = UrlRequestError.TIMED_OUT;
xunjieli 2015/10/13 23:07:11 What's the difference between TIMED_OUT and CONNEC
pauljensen 2015/11/05 18:35:28 I think CONNECTION_TIMED_OUT is just TIMED_OUT occ
48 /**
49 * Error code indicating the connection was closed unexpectedly.
50 */
51 public static final int ERROR_CONNECTION_CLOSED = UrlRequestError.CONNECTION _CLOSED;
52 /**
53 * Error code indicating the connection attempt timed out.
54 */
55 public static final int ERROR_CONNECTION_TIMED_OUT = UrlRequestError.CONNECT ION_TIMED_OUT;
56 /**
57 * Error code indicating the connection attempt was refused.
58 */
59 public static final int ERROR_CONNECTION_REFUSED = UrlRequestError.CONNECTIO N_REFUSED;
60 /**
61 * Error code indicating the connection was unexpectedly reset.
62 */
63 public static final int ERROR_CONNECTION_RESET = UrlRequestError.CONNECTION_ RESET;
64 /**
65 * Error code indicating the IP address being contacted is unreachable, mean ing there is no
66 * route to the specified host or network.
67 */
68 public static final int ERROR_ADDRESS_UNREACHABLE = UrlRequestError.ADDRESS_ UNREACHABLE;
69 /**
70 * Error code indicating another type of error was encountered. {@link #net Error} can be
xunjieli 2015/10/13 23:07:10 nit: there are two spaces after the period.
pauljensen 2015/11/05 18:35:28 Done.
71 * consulted to get a more specific cause.
72 */
73 public static final int ERROR_OTHER = UrlRequestError.OTHER;
74
75 /**
76 * Construct exception wrapping {@code cause} thrown by {@link UrlRequestLis tener}.
xunjieli 2015/10/13 23:07:11 nit: s/Construct/Constructs. Maybe this changes t
pauljensen 2015/11/05 18:35:29 Done.
77 *
78 * @param message explanation of failure.
79 * @param cause exception thrown by {@link UrlRequestListener} that's being wrapped.
80 */
81 public UrlRequestException(String message, Throwable cause) {
18 super(message, cause); 82 super(message, cause);
19 mNetError = 0; 83 mErrorCode = ERROR_LISTENER_THREW;
84 mCronetError = 0;
20 } 85 }
21 86
22 UrlRequestException(String message, int netError) { 87 /**
88 * Construct exception coming from Cronet failure.
xunjieli 2015/10/13 23:07:10 nit: s/Construct/Constructs. Embedder probably thi
pauljensen 2015/11/05 18:35:28 Done.
89 *
90 * @param message explanation of failure.
91 * @param errorCode error code, one of {@link #ERROR_LISTENER_THREW ERROR_*} .
92 * @param netError Cronet error code, one of
93 * <a href=https://chromium.googlesource.com/chromium/src/+/master/net/base/ net_error_list.h>
94 * these</a>.
95 */
96 public UrlRequestException(String message, int errorCode, int netError) {
23 super(message, null); 97 super(message, null);
24 mNetError = netError; 98 mErrorCode = errorCode;
99 mCronetError = netError;
xunjieli 2015/10/13 23:07:10 I don't really like that we call net error codes "
pauljensen 2015/11/05 18:35:28 I don't like "net" as the ERROR_* codes are all al
25 } 100 }
26 101
27 /** @return Error code if exception is reported by native. */ 102 /**
103 * Returns error code, one of {@link #ERROR_LISTENER_THREW ERROR_*}.
104 *
105 * @return error code, one of {@link #ERROR_LISTENER_THREW ERROR_*}.
106 */
107 public int getErrorCode() {
108 return mErrorCode;
109 }
110
111 /**
112 * Returns a Cronet error code. This may provide more specific error
113 * diagnosis than {@link #getErrorCode}, but the constant values are not exp osed to Java and
114 * may change over time. See
115 * <a href=https://chromium.googlesource.com/chromium/src/+/master/net/base/ net_error_list.h>
116 * here</a> for the lastest list of values.
117 *
118 * @return Cronet error code.
119 */
28 public int netError() { 120 public int netError() {
29 return mNetError; 121 return mCronetError;
122 }
123
124 /**
125 * Returns {@code true} if retrying this request right away might succeed, { @code false}
126 * otherwise. For example returns {@code true} when {@link #getErrorCode} re turns
127 * {@link #ERROR_NETWORK_CHANGED} because trying the request might succeed u sing the new
128 * network configuration, but {@code false} when {@code getErrorCode()} retu rns
129 * {@link #ERROR_INTERNET_DISCONNECTED} because retrying the request right a way will
130 * encounter the same failure (instead retrying should be delayed until devi ce regains
131 * network connectivity). Returns {@code false} when {@code getErrorCode()} returns
132 * {@link #ERROR_LISTENER_THREW}.
133 *
134 * @return {@code true} if retrying this request right away might succeed, { @code false}
135 * otherwise.
136 */
137 public boolean immediatelyRetryable() {
138 switch (mErrorCode) {
139 case ERROR_LISTENER_THREW:
140 case ERROR_HOSTNAME_NOT_RESOLVED:
141 case ERROR_INTERNET_DISCONNECTED:
142 case ERROR_CONNECTION_REFUSED:
143 case ERROR_ADDRESS_UNREACHABLE:
144 case ERROR_OTHER:
145 default:
146 return false;
147 case ERROR_NETWORK_CHANGED:
148 case ERROR_TIMED_OUT:
149 case ERROR_CONNECTION_CLOSED:
150 case ERROR_CONNECTION_TIMED_OUT:
151 case ERROR_CONNECTION_RESET:
152 return true;
153 }
30 } 154 }
31 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698