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

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

Introduction

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

Prototype

public int getStatusCode() 

Source Link

Document

Returns the status code 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 ww  w .j a  va2s  .c o 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   www.j a v  a2  s  .  co 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;
        }/* www .  j  av  a2 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:com.novartis.pcs.ontology.webapp.client.view.ErrorView.java

License:Apache License

@Override
public void onUncaughtException(Throwable e) {
    GWT.log("Unexpected exception", e);

    if (e instanceof UmbrellaException) {
        UmbrellaException umbrellaException = (UmbrellaException) e;
        if (umbrellaException.getCause() != null) {
            e = umbrellaException.getCause();
        }// ww w.  ja  v a 2s. c o  m
        if (umbrellaException.getCauses() != null) {
            for (Throwable cause : umbrellaException.getCauses()) {
                if (cause instanceof StatusCodeException) {
                    e = cause;
                    break;
                }
            }
        }
    }

    if (e instanceof StatusCodeException) {
        StatusCodeException statusCodeException = (StatusCodeException) e;
        if (statusCodeException.getStatusCode() == 401 || statusCodeException.getStatusCode() == 403) {
            errorLabel.setText("Unauthorized");
        } else {
            errorLabel.setText("HTTP status error: " + statusCodeException.getStatusCode());
        }
    } else {
        errorLabel.setText(e.getMessage());
    }
    dialogBox.center();
}

From source file:com.ponysdk.ui.terminal.UIBuilder.java

License:Apache License

public void onCommunicationError(final Throwable exception) {
    if (loadingMessageBox == null) {
        // log.log(Level.SEVERE, "Error ", exception);
        if (exception instanceof StatusCodeException) {
            final StatusCodeException codeException = (StatusCodeException) exception;
            if (codeException.getStatusCode() == 0)
                return;
        }//from  www.j av  a2s.c om
        Window.alert("Cannot inititialize the application : " + exception.getMessage() + "\n" + exception
                + "\nPlease reload your application");
    } else {
        if (pendingClose)
            return;
        // log.log(Level.SEVERE, "fireInstruction failed", exception);

        if (exception instanceof PonySessionException) {
            reload();
            return;
        }
        numberOfrequestInProgress--;
        showCommunicationErrorMessage(exception);
        hideLoadingMessageBox();
    }
}

From source file:com.ponysdk.ui.terminal.UIBuilder.java

License:Apache License

private void showCommunicationErrorMessage(final Throwable caught) {

    final VerticalPanel content = new VerticalPanel();
    if (caught instanceof StatusCodeException) {
        final StatusCodeException exception = (StatusCodeException) caught;
        content.add(new HTML("Server connection failed <br/>Code : " + exception.getStatusCode() + "<br/>"
                + "cause : " + exception.getMessage()));
    } else if (caught instanceof InvocationException) {
        content.add(new HTML("Exception durring server invocation : " + caught.getMessage()));
    } else {//from   w  w  w.  j a  v  a 2  s.  co m
        content.add(new HTML("Failure : " + caught == null ? "" : caught.getMessage()));
    }

    final HorizontalPanel actionPanel = new HorizontalPanel();
    actionPanel.setSize("100%", "100%");

    final Anchor reloadAnchor = new Anchor("reload");
    reloadAnchor.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            History.newItem("");
            reload();
        }
    });

    final Anchor closeAnchor = new Anchor("close");
    closeAnchor.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            communicationErrorMessagePanel.hide();
        }
    });

    actionPanel.add(reloadAnchor);
    actionPanel.add(closeAnchor);

    actionPanel.setCellHorizontalAlignment(reloadAnchor, HasHorizontalAlignment.ALIGN_CENTER);
    actionPanel.setCellHorizontalAlignment(closeAnchor, HasHorizontalAlignment.ALIGN_CENTER);
    actionPanel.setCellVerticalAlignment(reloadAnchor, HasVerticalAlignment.ALIGN_MIDDLE);
    actionPanel.setCellVerticalAlignment(closeAnchor, HasVerticalAlignment.ALIGN_MIDDLE);

    content.add(actionPanel);

    communicationErrorMessagePanel.setWidget(content);
    communicationErrorMessagePanel.setPopupPositionAndShow(new PositionCallback() {

        @Override
        public void setPosition(final int offsetWidth, final int offsetHeight) {
            communicationErrorMessagePanel.setPopupPosition((Window.getClientWidth() - offsetWidth) / 2,
                    (Window.getClientHeight() - offsetHeight) / 2);
        }
    });
}

From source file:com.tasktop.c2c.server.profile.web.ui.client.ExceptionMessageProvider.java

License:Open Source License

@Override
public List<String> getErrorMessages(Throwable exception) {
    if (exception instanceof ValidationFailedException) {
        return ((ValidationFailedException) exception).getMessages();
    } else if (exception instanceof AuthenticationFailedException) {
        if (exception.getMessage() == null) {
            return Collections.singletonList(profileMessages.invalidUsername());
        } else {//  www  .  j  ava2s.  co  m
            return Collections.singletonList(exception.getMessage());
        }
    } else if (ExceptionsUtil.isEntityNotFound(exception)) {
        return Collections.singletonList(profileMessages.entityNotFound() + " (404)");
    } else if (exception instanceof AuthenticationRequiredException) {
        SignInPlace.createPlace().go();
        return Collections.singletonList(exception.getMessage());
    } else if (exception instanceof StatusCodeException) {
        StatusCodeException statusCodeException = (StatusCodeException) exception;
        if (statusCodeException.getStatusCode() == 500) {
            return Collections.singletonList(profileMessages.unexpectedError() + " (HTTP 500)");
        } else {
            return Collections.singletonList(statusCodeException.getMessage());
        }
    } else if (exception instanceof DispatchException) {
        DispatchException dispatchException = (DispatchException) exception;
        if (dispatchException.getCauseClassname() != null
                && dispatchException.getCauseClassname().equals(ValidationFailedException.class.getName())) {
            return Arrays.asList(dispatchException.getMessage().split(","));
        }
        {
            return Collections.singletonList(dispatchException.getMessage());
        }
    }

    return Collections.singletonList(exception.getClass() + ": " + exception.getMessage());

}

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();//from   w  ww.  ja v a  2 s.c om
            return true;
        }
    }
    return false;
}

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

License:Apache License

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

        sce = (StatusCodeException) caught;
        if (sce.getStatusCode() == 403) {
            Window.alert("You do not have role ROLE_DEMO." + "\nAccess is forbidden!");
            return true;
        }/*from   www  .j  a  va 2  s .  co  m*/
    }
    return false;
}

From source file:edu.caltech.ipac.firefly.ui.PopupUtil.java

public static void showSevereError(final Throwable caught) {

    String eMsg = caught == null || caught.getMessage() == null ? "unknown" : caught.getMessage();
    GWT.log(eMsg, caught);//from   w  ww  .  j av  a  2 s.  c o  m

    String msgExtra = "<span class=\"faded-text\">"
            + "<br><br>If you still continue to receive this message, contact IRSA for <a href='http://irsa.ipac.caltech.edu/applications/Helpdesk' target='_blank'>help</a>.  "
            + "<span>";
    String title = "Error";
    String msg = "An unexpected error has occurred." + "<br>Caused by: " + eMsg;
    String details = null;

    if (caught instanceof IncompatibleRemoteServiceException) {
        title = "Application is out of date";
        msg = "This application is out of date.  In most cases, refreshing the page will resolve the problem.";
    } else if (caught instanceof StatusCodeException) {
        StatusCodeException scx = (StatusCodeException) caught;
        title = "Server is not available";
        details = eMsg;
        if (scx.getStatusCode() == 503) {
            msg = "The site is down for scheduled maintenance.";
            msgExtra = "";
        } else if (scx.getStatusCode() == 0) {
            title = "Server/Network is not available";
            msg = "If you are not connected to the internet, check your internet connection and try again";
        } else {
            msg = "The server encountered an unexpected condition which prevented it from fulfilling the request.<br>"
                    + "Refreshing the page may resolve the problem.";
        }
    } else if (caught instanceof RPCException) {
        RPCException ex = (RPCException) caught;
        details = ex.toHtmlString();
        if (ex.getEndUserMsg() != null) {
            msg = ex.getEndUserMsg();
        }
    }

    showMsgWithDetails(title, msg + msgExtra, PopupType.STANDARD, details, ERROR_MSG_STYLE);

}