Search in sources :

Example 1 with ServerException

use of org.eclipse.che.ide.commons.exception.ServerException in project che by eclipse.

the class CommitPresenter method handleError.

private void handleError(@NotNull Throwable exception) {
    if (exception instanceof ServerException && ((ServerException) exception).getErrorCode() == ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED) {
        dialogFactory.createMessageDialog(constant.commitTitle(), constant.committerIdentityInfoEmpty(), null).show();
        return;
    }
    String exceptionMessage = exception.getMessage();
    String errorMessage = (exceptionMessage != null && !exceptionMessage.isEmpty()) ? exceptionMessage : constant.commitFailed();
    GitOutputConsole console = gitOutputConsoleFactory.create(COMMIT_COMMAND_NAME);
    console.printError(errorMessage);
    consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
    notificationManager.notify(constant.commitFailed(), errorMessage, FAIL, FLOAT_MODE);
}
Also used : ServerException(org.eclipse.che.ide.commons.exception.ServerException) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)

Example 2 with ServerException

use of org.eclipse.che.ide.commons.exception.ServerException in project che by eclipse.

the class HistoryPresenterTest method shouldShowDialogOnInitCommitError.

@Test
public void shouldShowDialogOnInitCommitError() throws Exception {
    PromiseError error = mock(PromiseError.class);
    ServerException exception = mock(ServerException.class);
    when(exception.getErrorCode()).thenReturn(ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
    when(error.getCause()).thenReturn(exception);
    when(constant.initCommitWasNotPerformed()).thenReturn("error message");
    MessageDialog dialog = mock(MessageDialog.class);
    when(dialogFactory.createMessageDialog(eq("title"), eq("error message"), any(ConfirmCallback.class))).thenReturn(dialog);
    presenter.show();
    verify(logPromise).catchError(promiseErrorCaptor.capture());
    promiseErrorCaptor.getValue().apply(error);
    verify(dialog).show();
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) ServerException(org.eclipse.che.ide.commons.exception.ServerException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) MessageDialog(org.eclipse.che.ide.api.dialogs.MessageDialog) BaseTest(org.eclipse.che.ide.ext.git.client.BaseTest) Test(org.junit.Test)

Example 3 with ServerException

use of org.eclipse.che.ide.commons.exception.ServerException in project che by eclipse.

the class FindUsagesPresenter method findUsages.

public void findUsages(TextEditor activeEditor) {
    final VirtualFile virtualFile = activeEditor.getEditorInput().getFile();
    if (virtualFile instanceof Resource) {
        final Project project = ((Resource) virtualFile).getRelatedProject().get();
        if (project == null) {
            return;
        }
        final Optional<Resource> srcFolder = ((Resource) virtualFile).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) virtualFile);
        String projectPath = project.getLocation().toString();
        FindUsagesRequest request = dtoFactory.createDto(FindUsagesRequest.class);
        request.setFQN(fqn);
        request.setProjectPath(projectPath);
        request.setOffset(activeEditor.getCursorOffset());
        Promise<FindUsagesResponse> promise = searchService.findUsages(request);
        promise.then(new Operation<FindUsagesResponse>() {

            @Override
            public void apply(FindUsagesResponse arg) throws OperationException {
                handleResponse(arg);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError arg) throws OperationException {
                Throwable cause = arg.getCause();
                if (cause instanceof ServerException) {
                    handleError(((ServerException) cause).getHTTPStatus(), cause.getMessage());
                    return;
                }
                //in case websocket request
                if (cause instanceof org.eclipse.che.ide.websocket.rest.exceptions.ServerException) {
                    handleError(((org.eclipse.che.ide.websocket.rest.exceptions.ServerException) cause).getHTTPStatus(), cause.getMessage());
                    return;
                }
                Log.error(getClass(), arg);
                manager.notify(localizationConstant.failedToProcessFindUsage(), arg.getMessage(), FAIL, FLOAT_MODE);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) FindUsagesResponse(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse) ServerException(org.eclipse.che.ide.commons.exception.ServerException) FindUsagesRequest(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesRequest) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with ServerException

use of org.eclipse.che.ide.commons.exception.ServerException in project che by eclipse.

the class AsyncRequestCallback method handleFailure.

private void handleFailure(Response response) {
    Exception exception;
    String contentType = response.getHeader(CONTENT_TYPE);
    if (contentType != null && !contentType.contains(APPLICATION_JSON)) {
        String message = generateErrorMessage(response);
        exception = new Exception(message);
    } else {
        exception = new ServerException(response);
    }
    onFailure(exception);
}
Also used : ServerException(org.eclipse.che.ide.commons.exception.ServerException) ServerDisconnectedException(org.eclipse.che.ide.commons.exception.ServerDisconnectedException) UnauthorizedException(org.eclipse.che.ide.commons.exception.UnauthorizedException) ServerException(org.eclipse.che.ide.commons.exception.ServerException)

Example 5 with ServerException

use of org.eclipse.che.ide.commons.exception.ServerException in project che by eclipse.

the class MergePresenter method onMergeClicked.

/** {@inheritDoc} */
@Override
public void onMergeClicked() {
    view.close();
    final GitOutputConsole console = gitOutputConsoleFactory.create(MERGE_COMMAND_NAME);
    service.merge(appContext.getDevMachine(), project.getLocation(), selectedReference.getDisplayName()).then(new Operation<MergeResult>() {

        @Override
        public void apply(MergeResult result) throws OperationException {
            console.print(formMergeMessage(result));
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(formMergeMessage(result));
            project.synchronize();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            if (error.getCause() instanceof ServerException && ((ServerException) error.getCause()).getErrorCode() == ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED) {
                dialogFactory.createMessageDialog(constant.mergeTitle(), constant.committerIdentityInfoEmpty(), new ConfirmCallback() {

                    @Override
                    public void accepted() {
                    //do nothing
                    }
                }).show();
                return;
            }
            console.printError(error.getMessage());
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.mergeFailed(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) ServerException(org.eclipse.che.ide.commons.exception.ServerException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) MergeResult(org.eclipse.che.api.git.shared.MergeResult) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ServerException (org.eclipse.che.ide.commons.exception.ServerException)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)2 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)2 MergeResult (org.eclipse.che.api.git.shared.MergeResult)1 MessageDialog (org.eclipse.che.ide.api.dialogs.MessageDialog)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 ServerDisconnectedException (org.eclipse.che.ide.commons.exception.ServerDisconnectedException)1 UnauthorizedException (org.eclipse.che.ide.commons.exception.UnauthorizedException)1 BaseTest (org.eclipse.che.ide.ext.git.client.BaseTest)1 FindUsagesRequest (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesRequest)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1 Test (org.junit.Test)1 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)1