-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathOdeAsyncCallback.java
More file actions
57 lines (50 loc) · 1.97 KB
/
Copy pathOdeAsyncCallback.java
File metadata and controls
57 lines (50 loc) · 1.97 KB
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
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package com.google.appinventor.client;
import com.google.appinventor.client.output.OdeLog;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* Provides common functionality for asynchronous callbacks from the ODE
* client. Specifically, on failure, this does one of two things:
* <ol>
* <li> If a failure message was provided during construction,
* it is displayed using {@link ErrorReporter#reportError(String)}.
* <li> Otherwise, if the no-args constructor was used, the message in
* the exception passed to {@link #onFailure(Throwable)} is
* displayed using {@link ErrorReporter#reportError(String)}.
* </ol>
*
* @param <T> type of object returned by successful RPC call
*/
public abstract class OdeAsyncCallback<T> implements AsyncCallback<T> {
private String failureMessage;
/**
* Constructor for when caller wants subclass to display the message in
* the {@link Throwable} passed to {@link #onFailure(Throwable)}, rather
* than a static message provided at construction time
*/
public OdeAsyncCallback() {
}
/**
* Constructor allowing subclass to specify a message that should be
* displayed by {@link #onFailure(Throwable)}
*
* @param defaultFailureMessage message to display on failure
*/
public OdeAsyncCallback(String defaultFailureMessage) {
failureMessage = defaultFailureMessage;
}
@Override
public void onFailure(Throwable caught) {
String errorMessage =
(failureMessage == null) ? caught.getMessage() : failureMessage;
ErrorReporter.reportError(errorMessage);
OdeLog.elog("Got exception: " + caught.getMessage());
Throwable cause = caught.getCause();
if (cause != null) {
OdeLog.elog("Caused by: " + cause.getMessage());
}
}
}