Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.iceberg.exceptions;

import com.google.errorprone.annotations.FormatMethod;

/** Exception raised when attempting to load a warehouse that does not exist. */
public class NoSuchWarehouseException extends RuntimeException {
@FormatMethod
public NoSuchWarehouseException(String message, Object... args) {
super(String.format(message, args));
}

@FormatMethod
public NoSuchWarehouseException(Throwable cause, String message, Object... args) {
super(String.format(message, args), cause);
}
}
19 changes: 19 additions & 0 deletions core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.iceberg.exceptions.NoSuchPlanTaskException;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.NoSuchViewException;
import org.apache.iceberg.exceptions.NoSuchWarehouseException;
import org.apache.iceberg.exceptions.NotAuthorizedException;
import org.apache.iceberg.exceptions.RESTException;
import org.apache.iceberg.exceptions.ServiceFailureException;
Expand Down Expand Up @@ -87,6 +88,10 @@ public static Consumer<ErrorResponse> defaultErrorHandler() {
return DefaultErrorHandler.INSTANCE;
}

public static Consumer<ErrorResponse> configErrorHandler() {
return ConfigErrorHandler.INSTANCE;
}

public static Consumer<ErrorResponse> oauthErrorHandler() {
return OAuthErrorHandler.INSTANCE;
}
Expand Down Expand Up @@ -257,6 +262,20 @@ public void accept(ErrorResponse error) {
}
}

/** Request error handler for config endpoint. */
private static class ConfigErrorHandler extends DefaultErrorHandler {
private static final ErrorHandler INSTANCE = new ConfigErrorHandler();

@Override
public void accept(ErrorResponse error) {
if (error.code() == 404 && error.type() != null) {
throw new NoSuchWarehouseException("%s", error.message());
}

super.accept(error);
}
}

/**
* Request error handler that handles the common cases that are included with all responses, such
* as 400, 500, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ private static ConfigResponse fetchConfig(
queryParams.build(),
ConfigResponse.class,
RESTUtil.configHeaders(properties),
ErrorHandlers.defaultErrorHandler());
ErrorHandlers.configErrorHandler());
configResponse.validate();
return configResponse;
}
Expand Down
37 changes: 37 additions & 0 deletions core/src/test/java/org/apache/iceberg/rest/TestHTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
import org.apache.hc.core5.http.HttpStatus;
import org.apache.iceberg.IcebergBuild;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.NoSuchWarehouseException;
import org.apache.iceberg.exceptions.RESTException;
import org.apache.iceberg.exceptions.ServiceFailureException;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.rest.auth.AuthSession;
import org.apache.iceberg.rest.auth.TLSConfigurer;
Expand Down Expand Up @@ -645,4 +648,38 @@ public boolean equals(Object o) {
return Objects.equals(id, item.id) && Objects.equals(data, item.data);
}
}

@Test
public void testConfigErrorHandler404ThrowsNoSuchWarehouseException() {
ErrorResponse error =
ErrorResponse.builder()
.responseCode(404)
.withType("NotFoundException")
.withMessage("Warehouse not found")
.build();

assertThatThrownBy(() -> ErrorHandlers.configErrorHandler().accept(error))
.isInstanceOf(NoSuchWarehouseException.class)
.hasMessage("Warehouse not found");
}

@Test
public void testConfigErrorHandler404ForMisconfiguredUri() {
ErrorResponse error =
ErrorResponse.builder().responseCode(404).withMessage("Not Found").build();

assertThatThrownBy(() -> ErrorHandlers.configErrorHandler().accept(error))
.isInstanceOf(RESTException.class)
.hasMessageContaining("Not Found");
}

@Test
public void testConfigErrorHandlerDelegatesToDefaultForNon404() {
ErrorResponse error =
ErrorResponse.builder().responseCode(500).withMessage("Internal server error").build();

assertThatThrownBy(() -> ErrorHandlers.configErrorHandler().accept(error))
.isInstanceOf(ServiceFailureException.class)
.hasMessageContaining("Internal server error");
}
}
16 changes: 16 additions & 0 deletions open-api/rest-catalog-open-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ paths:
$ref: '#/components/responses/UnauthorizedResponse'
403:
$ref: '#/components/responses/ForbiddenResponse'
404:
$ref: '#/components/responses/NoSuchWarehouseResponse'
419:
$ref: '#/components/responses/AuthenticationTimeoutResponse'
503:
Expand Down Expand Up @@ -4660,6 +4662,20 @@ components:
}
}

NoSuchWarehouseResponse:
description: Not Found - The given warehouse does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/IcebergErrorResponse'
example: {
"error": {
"message": "The given warehouse does not exist",
"type": "NoSuchWarehouseException",
"code": 404
}
}

# Note that this is a representative example response for use as a shorthand in the spec.
# The fields `message` and `type` as indicated here are not presently prescriptive.
UnsupportedOperationResponse:
Expand Down