|
@@ -86,7 +86,7 @@ class ConnectInterceptor implements Interceptor {
|
|
|
headers.set(KEY_CONTENT_LENGTH, Long.toString(body.contentLength()));
|
|
|
headers.set(KEY_CONTENT_TYPE, body.contentType());
|
|
|
mConnection = connect(request);
|
|
|
- writeBody(body);
|
|
|
+ writeBody(request);
|
|
|
} else {
|
|
|
mConnection = connect(request);
|
|
|
}
|
|
@@ -112,7 +112,7 @@ class ConnectInterceptor implements Interceptor {
|
|
|
*/
|
|
|
private Connection connect(Request request) throws ConnectException {
|
|
|
if (!mNetwork.isAvailable())
|
|
|
- throw new NetworkError(String.format("Network Unavailable: %1$s.", request.url()));
|
|
|
+ throw new NetworkError(String.format("Network Unavailable: %1$s.", request.location()));
|
|
|
|
|
|
try {
|
|
|
Headers headers = request.headers();
|
|
@@ -123,25 +123,25 @@ class ConnectInterceptor implements Interceptor {
|
|
|
headers.set(KEY_HOST, uri.getHost());
|
|
|
return mFactory.connect(request);
|
|
|
} catch (URISyntaxException e) {
|
|
|
- throw new URLError(String.format("The url syntax error: %1$s.", request.url()), e);
|
|
|
+ throw new URLError(String.format("The url syntax error: %1$s.", request.location()), e);
|
|
|
} catch (MalformedURLException e) {
|
|
|
- throw new URLError(String.format("The url is malformed: %1$s.", request.url()), e);
|
|
|
+ throw new URLError(String.format("The url is malformed: %1$s.", request.location()), e);
|
|
|
} catch (UnknownHostException e) {
|
|
|
- throw new HostError(String.format("Hostname can not be resolved: %1$s.", request.url()), e);
|
|
|
+ throw new HostError(String.format("Hostname can not be resolved: %1$s.", request.location()), e);
|
|
|
} catch (SocketTimeoutException e) {
|
|
|
- throw new ConnectTimeoutError(String.format("Connect time out: %1$s.", request.url()), e);
|
|
|
+ throw new ConnectTimeoutError(String.format("Connect time out: %1$s.", request.location()), e);
|
|
|
} catch (Exception e) {
|
|
|
- throw new ConnectException(String.format("An unknown exception: %1$s.", request.url()), e);
|
|
|
+ throw new ConnectException(String.format("An unknown exception: %1$s.", request.location()), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void writeBody(RequestBody body) throws WriteException {
|
|
|
+ private void writeBody(Request request) throws WriteException {
|
|
|
try {
|
|
|
OutputStream stream = mConnection.getOutputStream();
|
|
|
- body.writeTo(IOUtils.toBufferedOutputStream(stream));
|
|
|
+ request.body().writeTo(IOUtils.toBufferedOutputStream(stream));
|
|
|
IOUtils.closeQuietly(stream);
|
|
|
} catch (Exception e) {
|
|
|
- throw new WriteException(e);
|
|
|
+ throw new WriteException(request.location(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -158,9 +158,9 @@ class ConnectInterceptor implements Interceptor {
|
|
|
ResponseBody body = new StreamBody(contentType, mConnection.getInputStream());
|
|
|
return Response.newBuilder().code(code).headers(headers).body(body).build();
|
|
|
} catch (SocketTimeoutException e) {
|
|
|
- throw new ReadTimeoutError(String.format("Read data time out: %1$s.", request.url()), e);
|
|
|
+ throw new ReadTimeoutError(String.format("Read data time out: %1$s.", request.location()), e);
|
|
|
} catch (Exception e) {
|
|
|
- throw new ReadException(e);
|
|
|
+ throw new ReadException(request.location(), e);
|
|
|
}
|
|
|
}
|
|
|
|