4646import  org .apache .zeppelin .notebook .Notebook ;
4747import  org .apache .zeppelin .notebook .Paragraph ;
4848import  org .apache .zeppelin .notebook .AuthorizationService ;
49+ import  org .apache .zeppelin .notebook .exception .NotePathAlreadyExistsException ;
4950import  org .apache .zeppelin .notebook .repo .NotebookRepoWithVersionControl ;
5051import  org .apache .zeppelin .notebook .scheduler .SchedulerService ;
5152import  org .apache .zeppelin .rest .exception .BadRequestException ;
53+ import  org .apache .zeppelin .rest .exception .ConflictException ;
5254import  org .apache .zeppelin .rest .exception .ForbiddenException ;
5355import  org .apache .zeppelin .rest .exception .NoteNotFoundException ;
5456import  org .apache .zeppelin .rest .exception .ParagraphNotFoundException ;
@@ -486,7 +488,15 @@ public Response exportNote(@PathParam("noteId") String noteId) throws IOExceptio
486488  @ ZeppelinApi 
487489  public  Response  importNote (@ QueryParam ("notePath" ) String  notePath , String  noteJson ) throws  IOException  {
488490    String  noteId  = notebookService .importNote (notePath , noteJson , getServiceContext (),
489-             new  RestServiceCallback <>());
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+             });
490500    return  new  JsonResponse <>(Status .OK , "" , noteId ).build ();
491501  }
492502
@@ -512,7 +522,15 @@ public Response createNote(String message) throws IOException {
512522            defaultInterpreterGroup ,
513523            request .getAddingEmptyParagraph (),
514524            getServiceContext (),
515-             new  RestServiceCallback <>());
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+             });
516534    return  notebook .processNote (noteId ,
517535      note  -> {
518536        AuthenticationInfo  subject  = new  AuthenticationInfo (authenticationService .getPrincipal ());
@@ -613,6 +631,13 @@ public void onSuccess(Note note, ServiceContext context) throws IOException {
613631                notebookServer .broadcastNote (note );
614632                notebookServer .broadcastNoteList (context .getAutheInfo (), context .getUserAndRoles ());
615633              }
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+               }
616641            });
617642    return  new  JsonResponse <>(Status .OK , "" ).build ();
618643  }
0 commit comments