mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-12-23 07:28:48 -05:00
improved error handling of DropboxFileStorage
This commit is contained in:
parent
fbd3aafe71
commit
2911119a24
@ -15,6 +15,7 @@ using KeePassLib.Serialization;
|
||||
using KeePassLib.Utility;
|
||||
using Keepass2android.Javafilestorage;
|
||||
using Exception = System.Exception;
|
||||
using FileNotFoundException = Java.IO.FileNotFoundException;
|
||||
|
||||
namespace keepass2android.Io
|
||||
{
|
||||
@ -42,8 +43,7 @@ namespace keepass2android.Io
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.Message);
|
||||
throw new Exception(e.Message, e);
|
||||
throw LogAndConvertJavaException(e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -56,8 +56,7 @@ namespace keepass2android.Io
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.Message);
|
||||
throw new Exception(e.Message, e);
|
||||
throw LogAndConvertJavaException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,16 +66,22 @@ namespace keepass2android.Io
|
||||
{
|
||||
return _jfs.OpenFileForRead(IocToPath(ioc));
|
||||
}
|
||||
catch (Java.IO.FileNotFoundException e)
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
throw new System.IO.FileNotFoundException(e.Message, e);
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.Message);
|
||||
throw new Exception(e.Message, e);
|
||||
throw LogAndConvertJavaException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static Exception LogAndConvertJavaException(Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.Message);
|
||||
var ex = new Exception(e.LocalizedMessage ?? e.Message, e);
|
||||
return ex;
|
||||
}
|
||||
|
||||
public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
|
||||
@ -111,8 +116,7 @@ namespace keepass2android.Io
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.Message);
|
||||
throw new Exception(e.Message, e);
|
||||
throw LogAndConvertJavaException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,10 +129,8 @@ namespace keepass2android.Io
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.Message);
|
||||
throw new Exception(e.Message, e);
|
||||
throw LogAndConvertJavaException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,8 +167,7 @@ namespace keepass2android.Io
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
throw new Exception(e.Message, e);
|
||||
LogAndConvertJavaException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,14 +195,12 @@ namespace keepass2android.Io
|
||||
|
||||
private static string IocToPath(IOConnectionInfo ioc)
|
||||
{
|
||||
int protocolLength = ioc.Path.IndexOf("://", System.StringComparison.Ordinal);
|
||||
int protocolLength = ioc.Path.IndexOf("://", StringComparison.Ordinal);
|
||||
|
||||
if (protocolLength < 0)
|
||||
return ioc.Path;
|
||||
else
|
||||
return ioc.Path.Substring(protocolLength + 3);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -82,8 +82,8 @@ public class DropboxFileStorage implements JavaFileStorage {
|
||||
storeKeys(tokens.key, tokens.secret);
|
||||
setLoggedIn(true);
|
||||
} catch (IllegalStateException e) {
|
||||
showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
|
||||
Log.i(TAG, "Error authenticating", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ public class DropboxFileStorage implements JavaFileStorage {
|
||||
}
|
||||
// do stuff with the Entry
|
||||
} catch (DropboxException e) {
|
||||
throw getNonDropboxException(e);
|
||||
throw convertException(e);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class DropboxFileStorage implements JavaFileStorage {
|
||||
com.dropbox.client2.DropboxAPI.Entry entry = mApi.metadata(path, 1, null, false, null);
|
||||
return entry.hash != previousFileVersion;
|
||||
} catch (DropboxException e) {
|
||||
throw getNonDropboxException(e);
|
||||
throw convertException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ public class DropboxFileStorage implements JavaFileStorage {
|
||||
return mApi.getFileStream(path, null);
|
||||
} catch (DropboxException e) {
|
||||
//System.out.println("Something went wrong: " + e);
|
||||
throw getNonDropboxException(e);
|
||||
throw convertException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,15 +174,15 @@ public class DropboxFileStorage implements JavaFileStorage {
|
||||
//TODO: it would be nice to be able to use the parent version with putFile()
|
||||
mApi.putFileOverwrite(path, bis, data.length, null);
|
||||
} catch (DropboxException e) {
|
||||
throw getNonDropboxException(e);
|
||||
throw convertException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Exception getNonDropboxException(DropboxException e) {
|
||||
private Exception convertException(DropboxException e) {
|
||||
|
||||
//TODO test for special error codes like 404
|
||||
Log.d(TAG, "Exception of type " +e.getClass().getName()+":" + e.getMessage());
|
||||
|
||||
//test for special error FileNotFound which must be reported with FileNotFoundException
|
||||
if (DropboxServerException.class.isAssignableFrom(e.getClass()) )
|
||||
{
|
||||
|
||||
@ -192,8 +192,6 @@ public class DropboxFileStorage implements JavaFileStorage {
|
||||
}
|
||||
|
||||
return e;
|
||||
//return new Exception(e.toString());
|
||||
|
||||
}
|
||||
|
||||
private void showToast(String msg) {
|
||||
|
Loading…
Reference in New Issue
Block a user