Skip to content

Commit 69ebbf1

Browse files
committed
Revert handling NotePathAlreadyExistsException in RestApi layer
1 parent aa0c2e2 commit 69ebbf1

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
import org.apache.zeppelin.notebook.Notebook;
4747
import org.apache.zeppelin.notebook.Paragraph;
4848
import org.apache.zeppelin.notebook.AuthorizationService;
49-
import org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException;
5049
import org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl;
5150
import org.apache.zeppelin.notebook.scheduler.SchedulerService;
5251
import org.apache.zeppelin.rest.exception.BadRequestException;
53-
import org.apache.zeppelin.rest.exception.ConflictException;
5452
import org.apache.zeppelin.rest.exception.ForbiddenException;
5553
import org.apache.zeppelin.rest.exception.NoteNotFoundException;
5654
import org.apache.zeppelin.rest.exception.ParagraphNotFoundException;
@@ -488,15 +486,7 @@ public Response exportNote(@PathParam("noteId") String noteId) throws IOExceptio
488486
@ZeppelinApi
489487
public Response importNote(@QueryParam("notePath") String notePath, String noteJson) throws IOException {
490488
String noteId = notebookService.importNote(notePath, noteJson, getServiceContext(),
491-
new RestServiceCallback<>() {
492-
@Override
493-
public void onFailure(Exception ex, ServiceContext context) throws IOException {
494-
if (ex instanceof NotePathAlreadyExistsException) {
495-
ex = new ConflictException(ex.getMessage());
496-
}
497-
super.onFailure(ex, context);
498-
}
499-
});
489+
new RestServiceCallback<>());
500490
return new JsonResponse<>(Status.OK, "", noteId).build();
501491
}
502492

@@ -522,15 +512,7 @@ public Response createNote(String message) throws IOException {
522512
defaultInterpreterGroup,
523513
request.getAddingEmptyParagraph(),
524514
getServiceContext(),
525-
new RestServiceCallback<>() {
526-
@Override
527-
public void onFailure(Exception ex, ServiceContext context) throws IOException {
528-
if (ex instanceof NotePathAlreadyExistsException) {
529-
ex = new ConflictException(ex.getMessage());
530-
}
531-
super.onFailure(ex, context);
532-
}
533-
});
515+
new RestServiceCallback<>());
534516
return notebook.processNote(noteId,
535517
note -> {
536518
AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
@@ -631,13 +613,6 @@ public void onSuccess(Note note, ServiceContext context) throws IOException {
631613
notebookServer.broadcastNote(note);
632614
notebookServer.broadcastNoteList(context.getAutheInfo(), context.getUserAndRoles());
633615
}
634-
@Override
635-
public void onFailure(Exception ex, ServiceContext context) throws IOException {
636-
if (ex instanceof NotePathAlreadyExistsException) {
637-
ex = new ConflictException(ex.getMessage());
638-
}
639-
super.onFailure(ex, context);
640-
}
641616
});
642617
return new JsonResponse<>(Status.OK, "").build();
643618
}

zeppelin-server/src/main/java/org/apache/zeppelin/rest/exception/WebApplicationExceptionMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import jakarta.ws.rs.ext.ExceptionMapper;
2323
import jakarta.ws.rs.ext.Provider;
2424

25+
import org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException;
26+
import org.apache.zeppelin.utils.ExceptionUtils;
2527
import org.slf4j.Logger;
2628
import org.slf4j.LoggerFactory;
2729

@@ -34,6 +36,8 @@ public class WebApplicationExceptionMapper implements ExceptionMapper<Throwable>
3436
public Response toResponse(Throwable exception) {
3537
if (exception instanceof WebApplicationException) {
3638
return ((WebApplicationException) exception).getResponse();
39+
} else if (exception instanceof NotePathAlreadyExistsException) {
40+
return ExceptionUtils.jsonResponseContent(Response.Status.CONFLICT, exception.getMessage());
3741
} else {
3842
LOGGER.error("Error response", exception);
3943
// Return generic error message to prevent information disclosure

0 commit comments

Comments
 (0)