Skip to content

Commit

Permalink
Core: Add CommitStateUnknownException handling to REST (apache#5694)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdblue authored Sep 2, 2022
1 parent 4a16fb1 commit f26861c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
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));
super(message, args);
}

@FormatMethod
public ServiceFailureException(Throwable cause, String message, Object... args) {
super(String.format(message, args), cause);
super(cause, message, args);
}
}
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.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(message, args);
}

@FormatMethod
public ServiceUnavailableException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}
}
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

0 comments on commit f26861c

Please sign in to comment.