private void addHashtag(String hashtags) { ChangeApi.hashtags(project.get(), changeId.get()) .post( PostInput.create(hashtags, null), new GerritCallback<JsArrayString>() { @Override public void onSuccess(JsArrayString result) { Gerrit.display( PageLinks.toChange(project, psId.getParentKey(), String.valueOf(psId.get()))); } @Override public void onFailure(Throwable err) { UIObject.setVisible(error, true); error.setInnerText( err instanceof StatusCodeException ? ((StatusCodeException) err).getEncodedResponse() : err.getMessage()); hashtagTextBox.setEnabled(true); } }); }
@Override public void onFailure(Throwable caught) { if (caught instanceof StatusCodeException) { GWT.reportUncaughtException(caught); } else { for (Request request : this.requests) { if (request.param.getCallbacks().isEmpty()) { GWT.reportUncaughtException(caught); } for (AsyncCallback requestCallback : request.param.getCallbacks()) { requestCallback.onFailure(caught); } } if (this.callback != null) { this.callback.onFailure(caught); } } }
@Test public void failureTest() { eventBus = new SimpleEventBus(); connectionFailedHandler = Mockito.mock(ConnectionFailedHandler.class); dispatcher = Mockito.spy(new TestDispatcher(connectionFailedHandler, eventBus)); dispatcher.setStatusIndicator(Mockito.mock(AsyncStatusIndicator.class)); Mockito.when(connectionFailedHandler.startRecover()).thenReturn(true); SuccessCallback<GetDescStoreResult> callback = Mockito.mock(SuccessCallback.class); dispatcher.execute(new GetDescStore(), callback); ArgumentCaptor<IneAsyncCallback> asyncCallbackCaptor = ArgumentCaptor .forClass(IneAsyncCallback.class); Mockito .verify(dispatcher) .doExecute(Mockito.any(Action.class), asyncCallbackCaptor.capture()); asyncCallbackCaptor.getValue().onFailure(new StatusCodeException(0, "")); dispatcher.onEvent(new ConnectionEvent(false)); asyncCallbackCaptor.getValue().onSuccess(result); Mockito.verify(callback).onSuccess(result); }
@Override public void onFailure(Throwable caught) { if (caught instanceof IncompatibleRemoteServiceException) { ErrorReporter.reportError("App Inventor has just been upgraded, you will need to press the reload button in your browser window"); return; } if (caught instanceof InvalidSessionException) { Ode.getInstance().invalidSessionDialog(); return; } if (caught instanceof ChecksumedFileException) { Ode.getInstance().corruptionDialog(); return; } if (caught instanceof BlocksTruncatedException) { OdeLog.log("Caught BlocksTruncatedException"); ErrorReporter.reportError("Caught BlocksTruncatedException"); return; } // SC_PRECONDITION_FAILED if our session has expired or login cookie // has become invalid if ((caught instanceof StatusCodeException) && ((StatusCodeException)caught).getStatusCode() == Response.SC_PRECONDITION_FAILED) { Ode.getInstance().sessionDead(); return; } 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()); } }
/** * Allows to get an exception message for the case the provided Throwable was tested to be a non SiteException. * @param e a Throwable object that is not child of the SiteException * @return the string corresponding to the proper error message */ public static String getNonSiteExceptionMessage( final Throwable e ) { if( e instanceof StatusCodeException ) { //In this case some of the RPC requests failed, and the exception is reported //In principle this means that a connection to the server was lost return I18NManager.getErrors().serverConnectionHasBeenLost(); } else { //Just report an unknown site error return I18NManager.getErrors().unknownInternalSiteError(); } }
@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(); } 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(); }
private String getServerError(final Throwable caught) { String eMsg = caught != null ? caught.getMessage() : "unknown"; 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 msg = "<b> Unable to load table.</b><br>"; if (caught instanceof StatusCodeException) { StatusCodeException scx = (StatusCodeException) caught; if (scx.getStatusCode() == 503) { msg = "The site is down for scheduled maintenance."; msgExtra = ""; } else if (scx.getStatusCode() == 0) { 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; if (ex.getEndUserMsg() != null) { eMsg = ex.getEndUserMsg(); } } return msg + eMsg + msgExtra; }
/** 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; } return sce.getStatusCode() == Response.SC_FORBIDDEN && (sce.getEncodedResponse().equals("Authentication required") || sce.getEncodedResponse().startsWith("Must be signed-in") || sce.getEncodedResponse().startsWith("Invalid authentication")); } return false; }
@Override public void onError(Request req, Throwable err) { if (!background) { RpcStatus.INSTANCE.onRpcComplete(); } if (err.getMessage().contains("XmlHttpRequest.status")) { cb.onFailure( new StatusCodeException(SC_UNAVAILABLE, RpcConstants.C.errorServerUnavailable())); } else { cb.onFailure(new StatusCodeException(SC_BAD_TRANSPORT, err.getMessage())); } }
private void doAddKey() { if (keyText.getText().isEmpty()) { return; } 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); } }); }
@Override protected boolean internalHandle(StatusCodeException error) { if (ErrorManager.get().hasErrorDisplayer()) { String title = ((ServerErrorConstants) this.getConstants()).serverErrorTitle(); ErrorManager.get().getErrorDisplayer().display(title, this.getErrorMessage(error), error, Severity.DANGER); } return true; }
@Override protected boolean internalHandle(StatusCodeException error) { if (ErrorManager.get().hasErrorDisplayer()) { String title = ((ClientErrorConstants) this.getConstants()).clientErrorTitle(); ErrorManager.get().getErrorDisplayer().display(title, this.getErrorMessage(error), error, Severity.DANGER); } return true; }
@Override public boolean handle(Throwable error) { if (!(error instanceof StatusCodeException)) { return false; } StatusCodeException statusCodeExc = (StatusCodeException) error; if (this.handlesCode(statusCodeExc.getStatusCode())) { return this.internalHandle(statusCodeExc); } return false; }
protected String getErrorMessage(StatusCodeException exception) { try { return this.constants.getString(this.constantsPrefix + exception.getStatusCode()); } catch (MissingResourceException exc) { return exception.getStatusText(); } }
/** * Exception handler. */ public static void handleException(Throwable caught, HasErrorMessage hasErrorMessage, ErrorMessageCustomizer errorMessageCustomizer) { boolean handled = false; if (caught instanceof StatusCodeException) { StatusCodeException sce = (StatusCodeException) caught; if (sce.getStatusCode() == Response.SC_UNAUTHORIZED) { onUnauthorized(); handled = true; } else if (sce.getStatusCode() == 0) { handleNetworkConnectionError(); handled = true; } } else if (caught instanceof IncompatibleRemoteServiceException) { MessageDialog.showMessageDialog(AlertPanel.Type.ERROR, constants.incompatibleRemoteService(), messages.incompatibleRemoteService()); handled = true; } if (!handled) { String message = parseErrorMessage(caught, errorMessageCustomizer); String[] lines = message.split("\r\n|\r|\n"); if (lines.length > 1 || (lines.length == 1 && lines[0].length() >= MAX_ERROR_LINE_LENGTH)) { MessageDialog.showMessageDialog(AlertPanel.Type.ERROR, constants.errorTitle(), message); } else { hasErrorMessage.setErrorMessage(message); } } }
protected void handleFailure(Throwable caught) { if (caught instanceof InvocationException || caught instanceof IncompatibleRemoteServiceException) { if (caught instanceof StatusCodeException) { handleStatusCodeException(caught); } else { handleUncheckedException(caught); } } else if (caught instanceof CheckedException) { handleCheckedException((CheckedException) caught); } else { handleUnknownException(caught); } }
private void onReceiving(int statusCode, String responseText, boolean connected) { if (statusCode != Response.SC_OK) { if (!connected) { super.disconnect(); listener.onError(new StatusCodeException(statusCode, responseText), connected); } } else { int index = responseText.lastIndexOf(SEPARATOR); if (index > read) { List<Serializable> messages = new ArrayList<Serializable>(); SplitResult data = separator.split(responseText.substring(read, index), index); int length = data.length(); for (int i = 0; i < length; i++) { if (disconnecting) { return; } String message = data.get(i); if (!message.isEmpty()) { parse(message, messages); } } read = index + 1; if (!messages.isEmpty()) { listener.onMessage(messages); } } if (!connected) { super.disconnected(); } } }
@Override public void onError(Throwable exception, boolean connected) { double errorTime = Duration.currentTimeMillis(); errorCount++; output("error " + errorCount + " " + (errorTime - startTime) + "ms " + connected + " " + exception, "lime"); assertTrue("status code exception", exception instanceof StatusCodeException); if (exception instanceof StatusCodeException) { assertEquals("status code", 417, ((StatusCodeException) exception).getStatusCode()); assertEquals("status message", "Oh Noes!", ((StatusCodeException) exception).getEncodedResponse()); } stop(); }
/** * refreshConnectedUsers */ private void refreshConnectedUsers() { getLoggedUsers = true; if (chatConnected) { chatService.getLoggedUsers(new AsyncCallback<List<GWTUser>>() { @Override public void onSuccess(List<GWTUser> result) { connectUsersList = result; usersConnected.setHTML(connectUsersList.size() + ""); getLoggedUsers = false; new Timer() { @Override public void run() { refreshConnectedUsers(); } }.schedule(USERS_IN_ROOM_REFRESHING_TIME); } @Override public void onFailure(Throwable caught) { Log.error(UserInfo.class + ".refreshConnectedUsers().onFailure(" + caught + ")"); getLoggedUsers = false; if (caught instanceof StatusCodeException && ((StatusCodeException) caught).getStatusCode() == 0) { new Timer() { @Override public void run() { refreshConnectedUsers(); } }.schedule(USERS_IN_ROOM_REFRESHING_TIME); } else { Main.get().showError("UserInfo.refreshConnectedUsers", caught); } } }); } else { getLoggedUsers = false; } }
/** * getPendingChatRoomUser */ private void getPendingChatRoomUser() { getPendingChatRoomUser = true; if (chatConnected) { chatService.getPendingChatRoomUser(new AsyncCallback<List<String>>() { @Override public void onSuccess(List<String> result) { for (String room : result) { ChatRoomPopup chatRoomPopup = new ChatRoomPopup("", room); chatRoomPopup.center(); chatRoomPopup.getPendingMessage(room); addChatRoom(chatRoomPopup); } getPendingChatRoomUser = false; new Timer() { @Override public void run() { getPendingChatRoomUser(); } }.schedule(NEW_ROOM_REFRESHING_TIME); } @Override public void onFailure(Throwable caught) { Log.error(UserInfo.class + ".getPendingChatRoomUser().onFailure(" + caught + ")"); getPendingChatRoomUser = false; if (caught instanceof StatusCodeException && ((StatusCodeException) caught).getStatusCode() == 0) { new Timer() { @Override public void run() { getPendingChatRoomUser(); } }.schedule(NEW_ROOM_REFRESHING_TIME); } else { Main.get().showError("UserInfo.getPendingChatRoomUser", caught); } } }); } else { getPendingChatRoomUser = false; } }
public static void showSevereError(final Throwable caught) { String eMsg= caught == null || caught.getMessage() == null ? "unknown" : caught.getMessage(); GWT.log(eMsg, caught); 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); }
/** True if err is a StatusCodeException with a specific HTTP code. */ public static boolean isStatus(Throwable err, int status) { return err instanceof StatusCodeException && ((StatusCodeException) err).getStatusCode() == status; }
/** Create a dialog box to nicely format an exception. */ public ErrorDialog(Throwable what) { this(); 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); m.getElement().getStyle().setProperty("whiteSpace", "pre"); body.add(m); } }
private void addReviewer(String reviewer, boolean confirmed) { if (reviewer.isEmpty()) { return; } ChangeApi.reviewers(project.get(), changeId.get()) .post( PostInput.create(reviewer, confirmed), new GerritCallback<PostResult>() { @Override public void onSuccess(PostResult result) { if (result.confirm()) { askForConfirmation(result.error()); } else if (result.error() != null) { UIObject.setVisible(error, true); error.setInnerText(result.error()); } else { UIObject.setVisible(error, false); error.setInnerText(""); suggestBox.setText(""); if (result.reviewers() != null && result.reviewers().length() > 0) { updateReviewerList(); } } } private void askForConfirmation(String text) { new ConfirmationDialog( Util.C.approvalTableAddManyReviewersConfirmationDialogTitle(), new SafeHtmlBuilder().append(text), new ConfirmationCallback() { @Override public void onOk() { addReviewer(reviewer, true); } }) .center(); } @Override public void onFailure(Throwable err) { if (isSigninFailure(err)) { new NotSignedInDialog().center(); } else { UIObject.setVisible(error, true); error.setInnerText( err instanceof StatusCodeException ? ((StatusCodeException) err).getEncodedResponse() : err.getMessage()); } } }); }
private void handleError(String statusCode, String encodedResponse) { this.fileId = null; progressBar.setValue(0); StyleUtils.addStyle(this, STYLE_ERROR); throw new StatusCodeException(Integer.parseInt(statusCode), encodedResponse); }
private void onError(int statusCode, String message) { listener.onError(new StatusCodeException(statusCode, message), false); }
protected abstract boolean internalHandle(StatusCodeException error);