rdblue commented on a change in pull request #4097: URL: https://github.com/apache/iceberg/pull/4097#discussion_r807137485
########## File path: core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java ########## @@ -0,0 +1,137 @@ +/* + * 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.rest; + +import java.io.IOException; +import java.util.function.Consumer; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.exceptions.BadRequestException; +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.rest.responses.ErrorResponse; + +/** + * A set of consumers to handle errors for requests for table entities or for namespace entities, + * to throw the correct exception. + */ +public class ErrorHandlers { + + private ErrorHandlers() { + } + + /** + * Table level error handlers. + * Should be chained wih the {@linkplain ErrorHandlers#defaultErrorHandler}, which takes care of common cases. + */ + public static Consumer<ErrorResponse> tableErrorHandler() { + return error -> { + + switch (error.code()) { + // table resource routes can encounter namespace not found or table not found. + // TODO - Need to define response types (can probably use the HTTP values and specialize from there). + case HttpStatus.SC_NOT_FOUND: + // TODO - error.type() could be null for HEAD responses. We probably want to pass Review comment: For HEAD requests, this should simply throw `NoSuchTableException` because the request is specifically for the table. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
