-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a grant already exists, return the appropriate response (#243)
- Loading branch information
1 parent
6f66848
commit eca6e70
Showing
8 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
polaris-core/src/main/java/org/apache/polaris/core/exceptions/AlreadyExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.polaris.core.exceptions; | ||
|
||
/** | ||
* A {@link PolarisException} implementation for when Polaris is unable to create an entity that | ||
* already exists. | ||
*/ | ||
public class AlreadyExistsException extends PolarisException { | ||
public AlreadyExistsException(String message) { | ||
super(message); | ||
} | ||
|
||
public AlreadyExistsException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
polaris-core/src/main/java/org/apache/polaris/core/exceptions/PolarisException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.polaris.core.exceptions; | ||
|
||
/** | ||
* Base class for Polaris-specific runtime exceptions. | ||
* | ||
* <p>All custom exceptions in Polaris should extend this class to provide specific error details. | ||
*/ | ||
public abstract class PolarisException extends RuntimeException { | ||
|
||
public PolarisException(String message) { | ||
super(message); | ||
} | ||
|
||
public PolarisException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...is-service/src/main/java/org/apache/polaris/service/exception/PolarisExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.polaris.service.exception; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.apache.iceberg.rest.responses.ErrorResponse; | ||
import org.apache.polaris.core.exceptions.AlreadyExistsException; | ||
import org.apache.polaris.core.exceptions.PolarisException; | ||
|
||
/** | ||
* An {@link ExceptionMapper} implementation for {@link PolarisException}s modeled after {@link | ||
* IcebergExceptionMapper} | ||
*/ | ||
@Provider | ||
public class PolarisExceptionMapper implements ExceptionMapper<PolarisException> { | ||
|
||
private Response.Status getStatus(PolarisException exception) { | ||
if (exception instanceof AlreadyExistsException) { | ||
return Response.Status.CONFLICT; | ||
} else { | ||
return Response.Status.INTERNAL_SERVER_ERROR; | ||
} | ||
} | ||
|
||
@Override | ||
public Response toResponse(PolarisException exception) { | ||
Response.Status status = getStatus(exception); | ||
ErrorResponse errorResponse = | ||
ErrorResponse.builder() | ||
.responseCode(status.getStatusCode()) | ||
.withType(exception.getClass().getSimpleName()) | ||
.withMessage(exception.getMessage()) | ||
.build(); | ||
return Response.status(status) | ||
.entity(errorResponse) | ||
.type(MediaType.APPLICATION_JSON_TYPE) | ||
.build(); | ||
} | ||
} |