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