Better error management, check Webdav instance unavailable, fixed crash on refresh when webdav instance was unavailable

This commit is contained in:
Daniele Verducci 2025-01-19 09:47:14 +01:00
parent 34ca6c1cd6
commit 744bfef62b
4 changed files with 57 additions and 16 deletions

View File

@ -123,7 +123,7 @@ class MainActivity : AppCompatActivity() {
showSettings() showSettings()
}) })
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({ findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({
loadLogbook(logbook.name) loadLogbookList()
}) })
findViewById<View>(R.id.button_sync).setOnClickListener({ findViewById<View>(R.id.button_sync).setOnClickListener({
loadLogbook(logbook.name) loadLogbook(logbook.name)
@ -375,15 +375,35 @@ class MainActivity : AppCompatActivity() {
} }
override fun onIOError(error: IOException) { override fun onIOError(error: IOException) {
TODO("Not yet implemented") Log.e(TAG, "Unable to load logbooks list (IOError): $error")
runOnUiThread({
setLoading(false)
onRepoError(getString(R.string.settings_network_error) + error.toString())
})
} }
override fun onWebDAVError(error: SardineException) { override fun onWebDAVError(error: SardineException) {
TODO("Not yet implemented") Log.e(TAG, "Unable to load logbooks list (SardineException): $error")
runOnUiThread({
setLoading(false)
onRepoError(
if(error.toString().contains("401")) {
getString(R.string.settings_webdav_error_denied)
} else if(error.toString().contains("503")) {
getString(R.string.settings_webdav_error_server_offline)
} else {
getString(R.string.settings_webdav_error_generic) + error.toString()
}
)
})
} }
override fun onError(error: Exception) { override fun onError(error: Exception) {
TODO("Not yet implemented") Log.e(TAG, "Unable to load logbooks list: $error")
runOnUiThread({
setLoading(false)
onRepoError(getString(R.string.settings_generic_error) + error.toString())
})
} }
}) })
} }
@ -412,6 +432,8 @@ class MainActivity : AppCompatActivity() {
onRepoError( onRepoError(
if(error.toString().contains("401")) { if(error.toString().contains("401")) {
getString(R.string.settings_webdav_error_denied) getString(R.string.settings_webdav_error_denied)
} else if(error.toString().contains("503")) {
getString(R.string.settings_webdav_error_server_offline)
} else { } else {
getString(R.string.settings_webdav_error_generic) + error.toString() getString(R.string.settings_webdav_error_generic) + error.toString()
} }
@ -475,6 +497,8 @@ class MainActivity : AppCompatActivity() {
onRepoError( onRepoError(
if(error.toString().contains("401")) { if(error.toString().contains("401")) {
getString(R.string.settings_webdav_error_denied) getString(R.string.settings_webdav_error_denied)
} else if(error.toString().contains("503")) {
getString(R.string.settings_webdav_error_server_offline)
} else { } else {
getString(R.string.settings_webdav_error_generic) + error.toString() getString(R.string.settings_webdav_error_generic) + error.toString()
} }
@ -573,6 +597,8 @@ class MainActivity : AppCompatActivity() {
onRepoError( onRepoError(
if(error.toString().contains("401")) { if(error.toString().contains("401")) {
getString(R.string.settings_webdav_error_denied) getString(R.string.settings_webdav_error_denied)
} else if(error.toString().contains("503")) {
getString(R.string.settings_webdav_error_server_offline)
} else { } else {
getString(R.string.settings_webdav_error_generic) + error.toString() getString(R.string.settings_webdav_error_generic) + error.toString()
} }

View File

@ -103,19 +103,32 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
listener: LogbookListObtainedListener listener: LogbookListObtainedListener
) { ) {
Thread(Runnable { Thread(Runnable {
val logbooksNames = arrayListOf<String>() try {
for (dr: DavResource in sardine.list(webDavURL)){ val logbooksNames = arrayListOf<String>()
if(!dr.name.startsWith(FILE_NAME_START)) for (dr: DavResource in sardine.list(webDavURL)){
continue if(!dr.name.startsWith(FILE_NAME_START))
if(!dr.name.endsWith(FILE_NAME_END)) continue
continue if(!dr.name.endsWith(FILE_NAME_END))
logbooksNames.add( continue
dr.name.replace("${FILE_NAME_START}_", "") logbooksNames.add(
.replace(FILE_NAME_START, "") dr.name.replace("${FILE_NAME_START}_", "")
.replace(FILE_NAME_END, "") .replace(FILE_NAME_START, "")
) .replace(FILE_NAME_END, "")
)
}
listener.onLogbookListObtained(logbooksNames)
} catch (e: SardineException) {
Log.e(TAG, e.toString())
listener.onWebDAVError(e)
} catch (e: IOException) {
Log.e(TAG, e.toString())
listener.onIOError(e)
} catch (e: SocketTimeoutException) {
Log.e(TAG, e.toString())
listener.onIOError(e)
} catch (e: Exception) {
listener.onError(e)
} }
listener.onLogbookListObtained(logbooksNames)
}).start() }).start()
} }

View File

@ -61,6 +61,7 @@
<string name="settings_storage_dav_pass">Password</string> <string name="settings_storage_dav_pass">Password</string>
<string name="settings_network_error">Impossibile raggiungere il server: </string> <string name="settings_network_error">Impossibile raggiungere il server: </string>
<string name="settings_webdav_error_denied">Nome utente o password WebDAV sbagliati</string> <string name="settings_webdav_error_denied">Nome utente o password WebDAV sbagliati</string>
<string name="settings_webdav_error_server_offline">Il server WebDAV non è al momento disponibile</string>
<string name="settings_webdav_error_generic">Si è verificato un errore tentando di accedere al server WebDAV:</string> <string name="settings_webdav_error_generic">Si è verificato un errore tentando di accedere al server WebDAV:</string>
<string name="settings_webdav_creation_error_generic">Impossibile creare un file di salvataggio sul server WebDAV:</string> <string name="settings_webdav_creation_error_generic">Impossibile creare un file di salvataggio sul server WebDAV:</string>
<string name="settings_webdav_creation_ok">Connessione al server WebDAV avvenuta con successo</string> <string name="settings_webdav_creation_ok">Connessione al server WebDAV avvenuta con successo</string>

View File

@ -75,6 +75,7 @@
<string name="settings_storage_dav_pass">Password</string> <string name="settings_storage_dav_pass">Password</string>
<string name="settings_network_error">Unable to reach server: </string> <string name="settings_network_error">Unable to reach server: </string>
<string name="settings_webdav_error_denied">Wrong WebDAV user or password</string> <string name="settings_webdav_error_denied">Wrong WebDAV user or password</string>
<string name="settings_webdav_error_server_offline">WebDAV server is currently unavailable</string>
<string name="settings_webdav_error_generic">Error while trying to access WebDAV:</string> <string name="settings_webdav_error_generic">Error while trying to access WebDAV:</string>
<string name="settings_webdav_creation_error_generic">Unable to save a file on the WebDAV server:</string> <string name="settings_webdav_creation_error_generic">Unable to save a file on the WebDAV server:</string>
<string name="settings_webdav_creation_ok">Successfully connected with WebDAV server</string> <string name="settings_webdav_creation_ok">Successfully connected with WebDAV server</string>