1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package org.openslx.dozmod.thrift;
import java.awt.Component;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.InvocationError;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.TInvalidDateParam;
import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.TTransferRejectedException;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.helper.MessageType;
public class ThriftError {
public static void showMessage(final Component parent, Logger logger, TException ex, String messageText) {
if (ex instanceof TNotFoundException) {
messageText += I18n.THRIFT.getString("ThriftError.Message.error.notFoundException");
} else if (ex instanceof TAuthorizationException) {
String reason = getString(((TAuthorizationException) ex).getNumber());
messageText += I18n.THRIFT.getString("ThriftError.Message.error.authorizationException",
reason, ex.getMessage());
} else if (ex instanceof TInvocationException) {
messageText += I18n.THRIFT.getString("ThriftError.Message.error.invocationException",
getString(((TInvocationException) ex).getNumber()), ex.getMessage());
} else if (ex instanceof TInvalidDateParam) {
messageText += I18n.THRIFT.getString("ThriftError.Message.error.invalidDateParam", ex.getMessage());
} else if (ex instanceof TTransferRejectedException) {
messageText += I18n.THRIFT.getString("ThriftError.Message.error.transferRejectedException",
ex.getMessage());
} else {
messageText += I18n.THRIFT.getString("ThriftError.Message.error.unexpectedException",
ex.getClass().getSimpleName());
}
if (logger != null) {
logger.warn("A thrift call raised an exception", ex);
}
if (SwingUtilities.isEventDispatchThread()) {
Gui.showMessageBox(parent, messageText, MessageType.ERROR, null, null);
return;
}
final String msg = messageText;
Gui.asyncExec(new Runnable() {
@Override
public void run() {
Gui.showMessageBox(parent, msg, MessageType.ERROR, null, null);
}
});
}
private static String getString(InvocationError error) {
if (error == null)
return I18n.THRIFT.getString("ThriftError.InvocationError.null");
switch (error) {
case INTERNAL_SERVER_ERROR:
return I18n.THRIFT.getString("ThriftError.InvocationError.internalServerError");
case INVALID_DATA:
return I18n.THRIFT.getString("ThriftError.InvocationError.invalidData");
case INVALID_SHARE_MODE:
return I18n.THRIFT.getString("ThriftError.InvocationError.invalidShareMode");
case MISSING_DATA:
return I18n.THRIFT.getString("ThriftError.InvocationError.missingData");
case UNKNOWN_IMAGE:
return I18n.THRIFT.getString("ThriftError.InvocationError.unknownImage");
case UNKNOWN_LECTURE:
return I18n.THRIFT.getString("ThriftError.InvocationError.unknownLecture");
case UNKNOWN_USER:
return I18n.THRIFT.getString("ThriftError.InvocationError.unknownUser");
default:
return I18n.THRIFT.getString("ThriftError.InvocationError.default", error.toString());
}
}
public static String getString(AuthorizationError error) {
if (error == null)
return I18n.THRIFT.getString("ThriftError.AuthorizationError.null");
switch (error) {
case ACCOUNT_SUSPENDED:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.accountSuspended");
case BANNED_NETWORK:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.bannedNetwork");
case CHALLENGE_FAILED:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.challengeFailed");
case GENERIC_ERROR:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.genericError");
case INVALID_CREDENTIALS:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.invalidCredentials");
case INVALID_KEY:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.invalidKey");
case INVALID_ORGANIZATION:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.invalidOrganization");
case INVALID_TOKEN:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.invalidToken");
case NOT_AUTHENTICATED:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.notAuthenticated");
case NO_PERMISSION:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.noPermission");
case ORGANIZATION_SUSPENDED:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.organizationSuspended");
default:
return I18n.THRIFT.getString("ThriftError.AuthorizationError.default", error.toString());
}
}
private static final String[] ignoredMethods = { "ping", "getStatus", "updateBlockHashes",
"cancelUpload", "cancelDownload" };
public static boolean failSilently(String methodName) {
for (int i = 0; i < ignoredMethods.length; ++i) {
if (ignoredMethods[i].equals(methodName))
return true;
}
return false;
}
}
|