mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-07 07:56:14 +00:00
Enhance connection error messages
Handle each exception in OCHttpClient::execute separately to help diagnose
This commit is contained in:
parent
141dfa40ed
commit
580d4c1588
@ -32,6 +32,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@ -152,29 +153,8 @@ public class OCHttpClient {
|
||||
HttpURLConnection urlConnection = null;
|
||||
try {
|
||||
urlConnection = (HttpURLConnection) url.openConnection();
|
||||
urlConnection.setRequestMethod(method);
|
||||
urlConnection.setRequestProperty("User-Agent", _userAgent);
|
||||
urlConnection.setInstanceFollowRedirects(true);
|
||||
if (!"GET".equals(method)) {
|
||||
urlConnection.setDoOutput(true);
|
||||
}
|
||||
urlConnection.setRequestProperty("Content-Type", "application/json");
|
||||
urlConnection.setRequestProperty("Accept", "application/json");
|
||||
urlConnection.setRequestProperty("Transfer-Encoding", "chunked");
|
||||
|
||||
String basicAuth = "Basic " +
|
||||
Base64.encodeToString((_username + ":" + _password).getBytes(), Base64.NO_WRAP);
|
||||
urlConnection.setRequestProperty("Authorization", basicAuth);
|
||||
urlConnection.setChunkedStreamingMode(0);
|
||||
|
||||
if (!"GET".equals(method)) {
|
||||
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
|
||||
out.write(requestBody.getBytes(Charset.forName("UTF-8")));
|
||||
out.close();
|
||||
}
|
||||
|
||||
response = handleHTTPResponse(urlConnection, skipError);
|
||||
} catch (IOException e) {
|
||||
Log.e(OCHttpClient.TAG, "Failed to open connection to server: " + e);
|
||||
throw new OCSyncException(R.string.err_sync_http_request_ioexception, OCSyncErrorType.IO);
|
||||
} finally {
|
||||
if (urlConnection != null) {
|
||||
@ -182,6 +162,43 @@ public class OCHttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
if (urlConnection == null) {
|
||||
Log.e(OCHttpClient.TAG, "Failed to open connection to server: null urlConnection");
|
||||
throw new OCSyncException(R.string.err_sync_http_request_ioexception, OCSyncErrorType.IO);
|
||||
}
|
||||
|
||||
try {
|
||||
urlConnection.setRequestMethod(method);
|
||||
} catch (ProtocolException e) {
|
||||
Log.e(OCHttpClient.TAG, "Fatal error when setting request method: " + e);
|
||||
throw new OCSyncException(R.string.err_sync_http_request_ioexception, OCSyncErrorType.IO);
|
||||
}
|
||||
urlConnection.setRequestProperty("User-Agent", _userAgent);
|
||||
urlConnection.setInstanceFollowRedirects(true);
|
||||
if (!"GET".equals(method)) {
|
||||
urlConnection.setDoOutput(true);
|
||||
}
|
||||
urlConnection.setRequestProperty("Content-Type", "application/json");
|
||||
urlConnection.setRequestProperty("Accept", "application/json");
|
||||
urlConnection.setRequestProperty("Transfer-Encoding", "chunked");
|
||||
|
||||
String basicAuth = "Basic " +
|
||||
Base64.encodeToString((_username + ":" + _password).getBytes(), Base64.NO_WRAP);
|
||||
urlConnection.setRequestProperty("Authorization", basicAuth);
|
||||
urlConnection.setChunkedStreamingMode(0);
|
||||
|
||||
if (!"GET".equals(method)) {
|
||||
try {
|
||||
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
|
||||
out.write(requestBody.getBytes(Charset.forName("UTF-8")));
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(OCHttpClient.TAG, "Failed to open connection to server: " + e);
|
||||
throw new OCSyncException(R.string.err_sync_http_write_failed, OCSyncErrorType.IO);
|
||||
}
|
||||
}
|
||||
|
||||
response = handleHTTPResponse(urlConnection, skipError);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -183,4 +183,5 @@
|
||||
<string name="no_confirm">No</string>
|
||||
<string name="pref_show_sync_notifications">Show sync notifications</string>
|
||||
<string name="sync_complete">Synchronisation complete</string>
|
||||
<string name="err_sync_http_write_failed">Error #19: Failed to write HTTP stream when pushing data to server.</string>
|
||||
</resources>
|
||||
|
@ -159,5 +159,6 @@
|
||||
<string name="no_confirm">No</string>
|
||||
<string name="pref_show_sync_notifications">Show sync notifications</string>
|
||||
<string name="sync_complete">Synchronization complete</string>
|
||||
<string name="err_sync_http_write_failed">Error #19: Failed to write HTTP stream when pushing data to server.</string>
|
||||
|
||||
</resources>
|
||||
|
@ -183,4 +183,5 @@
|
||||
<string name="no_confirm">Non</string>
|
||||
<string name="pref_show_sync_notifications">Afficher les notifications de synchronisation</string>
|
||||
<string name="sync_complete">Synchronisation terminée</string>
|
||||
<string name="err_sync_http_write_failed">Erreur #19: échec d\'écriture du flux HTTP lors de la poussée d\'informations vers le serveur.</string>
|
||||
</resources>
|
||||
|
@ -272,4 +272,5 @@
|
||||
<string name="no_confirm">No</string>
|
||||
<string name="pref_show_sync_notifications">Show sync notifications</string>
|
||||
<string name="sync_complete">Synchronization complete</string>
|
||||
<string name="err_sync_http_write_failed">Error #19: Failed to write HTTP stream when pushing data to server.</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user