Example usage for com.google.gwt.user.client.rpc StatusCodeException getEncodedResponse

List of usage examples for com.google.gwt.user.client.rpc StatusCodeException getEncodedResponse

Introduction

In this page you can find the example usage for com.google.gwt.user.client.rpc StatusCodeException getEncodedResponse.

Prototype

public String getEncodedResponse() 

Source Link

Document

Returns the response message associated with the failed request.

Usage

From source file:com.google.gerrit.client.account.MyGpgKeysScreen.java

License:Apache License

private void doAddKey() {
    if (keyText.getText().isEmpty()) {
        return;//from  w w  w.ja v  a  2s .  co  m
    }
    addButton.setEnabled(false);
    keyText.setEnabled(false);
    AccountApi.addGpgKey("self", keyText.getText(), new AsyncCallback<NativeMap<GpgKeyInfo>>() {
        @Override
        public void onSuccess(NativeMap<GpgKeyInfo> result) {
            keyText.setEnabled(true);
            refreshKeys();
        }

        @Override
        public void onFailure(Throwable caught) {
            keyText.setEnabled(true);
            addButton.setEnabled(true);
            if (caught instanceof StatusCodeException) {
                StatusCodeException sce = (StatusCodeException) caught;
                if (sce.getStatusCode() == Response.SC_CONFLICT
                        || sce.getStatusCode() == Response.SC_BAD_REQUEST) {
                    errorText.setText(sce.getEncodedResponse());
                } else {
                    errorText.setText(sce.getMessage());
                }
            } else {
                errorText.setText("Unexpected error saving key: " + caught.getMessage());
            }
            errorPanel.setVisible(true);
        }
    });
}

From source file:com.google.gerrit.client.ErrorDialog.java

License:Apache License

/** Create a dialog box to nicely format an exception. */
public ErrorDialog(final Throwable what) {
    this();//from   w  w  w.j  a va 2  s .  c o m

    String hdr;
    String msg;

    if (what instanceof StatusCodeException) {
        StatusCodeException sc = (StatusCodeException) what;
        if (RestApi.isExpected(sc.getStatusCode())) {
            hdr = null;
            msg = sc.getEncodedResponse();
        } else if (sc.getStatusCode() == Response.SC_INTERNAL_SERVER_ERROR) {
            hdr = null;
            msg = what.getMessage();
        } else {
            hdr = RpcConstants.C.errorServerUnavailable();
            msg = what.getMessage();
        }

    } else if (what instanceof RemoteJsonException) {
        // TODO Remove RemoteJsonException from Gerrit sources.
        hdr = RpcConstants.C.errorRemoteJsonException();
        msg = what.getMessage();

    } else {
        // TODO Fix callers of ErrorDialog to stop passing random types.
        hdr = what.getClass().getName();
        if (hdr.startsWith("java.lang.")) {
            hdr = hdr.substring("java.lang.".length());
        } else if (hdr.startsWith("com.google.gerrit.")) {
            hdr = hdr.substring(hdr.lastIndexOf('.') + 1);
        }
        if (hdr.endsWith("Exception")) {
            hdr = hdr.substring(0, hdr.length() - "Exception".length());
        } else if (hdr.endsWith("Error")) {
            hdr = hdr.substring(0, hdr.length() - "Error".length());
        }
        msg = what.getMessage();
    }

    if (hdr != null) {
        final Label r = new Label(hdr);
        r.setStyleName(Gerrit.RESOURCES.css().errorDialogErrorType());
        body.add(r);
    }

    if (msg != null) {
        final Label m = new Label(msg);
        DOM.setStyleAttribute(m.getElement(), "whiteSpace", "pre");
        body.add(m);
    }
}

From source file:com.google.gerrit.client.rpc.RestApi.java

License:Apache License

/** True if err is describing a user that is currently anonymous. */
public static boolean isNotSignedIn(Throwable err) {
    if (err instanceof StatusCodeException) {
        StatusCodeException sce = (StatusCodeException) err;
        if (sce.getStatusCode() == Response.SC_UNAUTHORIZED) {
            return true;
        }//from  w  w  w .  j a v a 2 s  .c  om
        return sce.getStatusCode() == Response.SC_FORBIDDEN
                && (sce.getEncodedResponse().equals("Authentication required")
                        || sce.getEncodedResponse().startsWith("Must be signed-in"));
    }
    return false;
}

From source file:de.itsvs.cwtrpc.sample1.client.SampleView.java

License:Apache License

protected boolean checkInvalidSession(Throwable caught) {
    if (caught instanceof StatusCodeException) {
        final StatusCodeException sce;

        sce = (StatusCodeException) caught;
        if ((sce.getStatusCode() == 400) && "INVALID_SESSION".equals(sce.getEncodedResponse())) {
            handleInvalidSession();// www  . ja  v a  2s  .  c  o m
            return true;
        }
    }
    return false;
}