Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Add CommitStateUnknownException handling to REST #5694

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -21,7 +21,7 @@
import com.google.errorprone.annotations.FormatMethod;

/** Exception thrown on HTTP 5XX Server Error. */
public class ServiceFailureException extends RuntimeException {
public class ServiceFailureException extends RESTException {
@FormatMethod
public ServiceFailureException(String message, Object... args) {
super(String.format(message, args));
Expand Down
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.iceberg.exceptions;

import com.google.errorprone.annotations.FormatMethod;

/** Exception thrown on HTTP 503: service is unavailable */
public class ServiceUnavailableException extends RESTException {
@FormatMethod
public ServiceUnavailableException(String message, Object... args) {
super(String.format(message, args));
}

@FormatMethod
public ServiceUnavailableException(Throwable cause, String message, Object... args) {
super(String.format(message, args), cause);
}
}
12 changes: 10 additions & 2 deletions core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.exceptions.BadRequestException;
import org.apache.iceberg.exceptions.CommitFailedException;
import org.apache.iceberg.exceptions.CommitStateUnknownException;
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.NotAuthorizedException;
import org.apache.iceberg.exceptions.RESTException;
import org.apache.iceberg.exceptions.ServiceFailureException;
import org.apache.iceberg.exceptions.ServiceUnavailableException;
import org.apache.iceberg.rest.responses.ErrorResponse;

/**
Expand Down Expand Up @@ -57,6 +59,10 @@ private static Consumer<ErrorResponse> baseCommitErrorHandler() {
throw new NoSuchTableException("%s", error.message());
case 409:
throw new CommitFailedException("Commit failed: %s", error.message());
case 500:
case 504:
throw new CommitStateUnknownException(
new ServiceFailureException("Service failed: %s: %s", error.code(), error.message()));
}
};
}
Expand Down Expand Up @@ -113,10 +119,12 @@ public static Consumer<ErrorResponse> defaultErrorHandler() {
case 405:
case 406:
break;
case 501:
throw new UnsupportedOperationException(error.message());
case 500:
throw new ServiceFailureException("Server error: %s: %s", error.type(), error.message());
case 501:
throw new UnsupportedOperationException(error.message());
case 503:
throw new ServiceUnavailableException("Service unavailable: %s", error.message());
}

throw new RESTException("Unable to process: %s", error.message());
Expand Down