Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zeppelin.rest.exception;

import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import org.apache.zeppelin.utils.ExceptionUtils;

/**
* ConflictException handler for WebApplicationException
*/
public class ConflictException extends WebApplicationException {
private static Response conflictJson(String message) {
return ExceptionUtils.jsonResponseContent(Response.Status.CONFLICT, message);
}

public ConflictException(String message) {
super(conflictJson(message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

import org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException;
import org.apache.zeppelin.utils.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,6 +36,8 @@ public class WebApplicationExceptionMapper implements ExceptionMapper<Throwable>
public Response toResponse(Throwable exception) {
if (exception instanceof WebApplicationException) {
return ((WebApplicationException) exception).getResponse();
} else if (exception instanceof NotePathAlreadyExistsException) {
return ExceptionUtils.jsonResponseContent(Response.Status.CONFLICT, exception.getMessage());
} else {
LOGGER.error("Error response", exception);
// Return generic error message to prevent information disclosure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ public String importNote(String notePath,
callback.onSuccess(note, context);
return note.getId();
});

} catch (NotePathAlreadyExistsException e) {
callback.onFailure(new NotePathAlreadyExistsException("Fail to import note: " + e.getMessage(), e), context);
return null;
} catch (IOException e) {
callback.onFailure(new IOException("Fail to import note: " + e.getMessage(), e), context);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public NotePathAlreadyExistsException(final String message) {
super(message);
}

public NotePathAlreadyExistsException(final String message, final Throwable cause) {
super(message, cause);
}

}
Loading