mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-31 02:17:53 +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.io.OutputStream; | ||||||
| import java.net.HttpURLConnection; | import java.net.HttpURLConnection; | ||||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||||
|  | import java.net.ProtocolException; | ||||||
| import java.net.URL; | import java.net.URL; | ||||||
| import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||||
| 
 | 
 | ||||||
| @ -152,7 +153,26 @@ public class OCHttpClient { | |||||||
| 		HttpURLConnection urlConnection = null; | 		HttpURLConnection urlConnection = null; | ||||||
| 		try { | 		try { | ||||||
| 			urlConnection = (HttpURLConnection) url.openConnection(); | 			urlConnection = (HttpURLConnection) url.openConnection(); | ||||||
|  | 		} 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) { | ||||||
|  | 				urlConnection.disconnect(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		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); | 			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.setRequestProperty("User-Agent", _userAgent); | ||||||
| 		urlConnection.setInstanceFollowRedirects(true); | 		urlConnection.setInstanceFollowRedirects(true); | ||||||
| 		if (!"GET".equals(method)) { | 		if (!"GET".equals(method)) { | ||||||
| @ -168,20 +188,17 @@ public class OCHttpClient { | |||||||
| 		urlConnection.setChunkedStreamingMode(0); | 		urlConnection.setChunkedStreamingMode(0); | ||||||
| 
 | 
 | ||||||
| 		if (!"GET".equals(method)) { | 		if (!"GET".equals(method)) { | ||||||
|  | 			try { | ||||||
| 				OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); | 				OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); | ||||||
| 				out.write(requestBody.getBytes(Charset.forName("UTF-8"))); | 				out.write(requestBody.getBytes(Charset.forName("UTF-8"))); | ||||||
| 				out.close(); | 				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); | 		response = handleHTTPResponse(urlConnection, skipError); | ||||||
| 		} catch (IOException e) { |  | ||||||
| 			throw new OCSyncException(R.string.err_sync_http_request_ioexception, OCSyncErrorType.IO); |  | ||||||
| 		} finally { |  | ||||||
| 			if (urlConnection != null) { |  | ||||||
| 				urlConnection.disconnect(); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		return response; | 		return response; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -183,4 +183,5 @@ | |||||||
|     <string name="no_confirm">No</string> |     <string name="no_confirm">No</string> | ||||||
|     <string name="pref_show_sync_notifications">Show sync notifications</string> |     <string name="pref_show_sync_notifications">Show sync notifications</string> | ||||||
|     <string name="sync_complete">Synchronisation complete</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> | </resources> | ||||||
|  | |||||||
| @ -159,5 +159,6 @@ | |||||||
|     <string name="no_confirm">No</string> |     <string name="no_confirm">No</string> | ||||||
|     <string name="pref_show_sync_notifications">Show sync notifications</string> |     <string name="pref_show_sync_notifications">Show sync notifications</string> | ||||||
|     <string name="sync_complete">Synchronization complete</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> | </resources> | ||||||
|  | |||||||
| @ -183,4 +183,5 @@ | |||||||
|     <string name="no_confirm">Non</string> |     <string name="no_confirm">Non</string> | ||||||
|     <string name="pref_show_sync_notifications">Afficher les notifications de synchronisation</string> |     <string name="pref_show_sync_notifications">Afficher les notifications de synchronisation</string> | ||||||
|     <string name="sync_complete">Synchronisation terminée</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> | </resources> | ||||||
|  | |||||||
| @ -272,4 +272,5 @@ | |||||||
|     <string name="no_confirm">No</string> |     <string name="no_confirm">No</string> | ||||||
|     <string name="pref_show_sync_notifications">Show sync notifications</string> |     <string name="pref_show_sync_notifications">Show sync notifications</string> | ||||||
|     <string name="sync_complete">Synchronization complete</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> | </resources> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user