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);
}
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();
}
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);
}
});
}
}
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);
}
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);
}
});
}
Aggregations