HuaHuaY commented on code in PR #296:
URL: https://github.com/apache/iceberg-cpp/pull/296#discussion_r2563940472


##########
src/iceberg/catalog/rest/types.h:
##########
@@ -19,7 +19,6 @@
 
 #pragma once
 
-#include <algorithm>
 #include <format>

Review Comment:
   
   ```suggestion
   ```
   Help to remove the unused header file.



##########
src/iceberg/catalog/rest/rest_util.cc:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/catalog/rest/rest_util.h"
+
+#include <cpr/util.h>
+
+#include "iceberg/table_identifier.h"
+#include "iceberg/util/macros.h"
+namespace iceberg::rest {

Review Comment:
   
   ```suggestion
   #include "iceberg/util/macros.h"
   
   namespace iceberg::rest {
   ```



##########
src/iceberg/catalog/rest/http_client.cc:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/catalog/rest/http_client.h"
+
+#include <cpr/cpr.h>
+#include <nlohmann/json.hpp>
+
+#include "iceberg/catalog/rest/constant.h"
+#include "iceberg/catalog/rest/error_handlers.h"
+#include "iceberg/catalog/rest/json_internal.h"
+#include "iceberg/json_internal.h"
+#include "iceberg/result.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg::rest {
+
+class HttpResponse::Impl {
+ public:
+  explicit Impl(cpr::Response&& response) : response_(std::move(response)) {}
+  ~Impl() = default;
+
+  int32_t status_code() const { return 
static_cast<int32_t>(response_.status_code); }
+
+  std::string body() const { return response_.text; }
+
+  std::unordered_map<std::string, std::string> headers() const {
+    return {response_.header.begin(), response_.header.end()};
+  }
+
+ private:
+  cpr::Response response_;
+};
+
+HttpResponse::HttpResponse(HttpResponse&&) noexcept = default;
+HttpResponse& HttpResponse::operator=(HttpResponse&&) noexcept = default;
+HttpResponse::HttpResponse() = default;
+HttpResponse::~HttpResponse() = default;

Review Comment:
   
   ```suggestion
   HttpResponse::HttpResponse() = default;
   HttpResponse::~HttpResponse() = default;
   HttpResponse::HttpResponse(HttpResponse&&) noexcept = default;
   HttpResponse& HttpResponse::operator=(HttpResponse&&) noexcept = default;
   ```



##########
src/iceberg/catalog/rest/error_handlers.h:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include "iceberg/catalog/rest/iceberg_rest_export.h"
+#include "iceberg/catalog/rest/type_fwd.h"
+#include "iceberg/result.h"
+
+/// \file iceberg/catalog/rest/error_handlers.h
+/// Error handlers for different HTTP error types in Iceberg REST API.
+
+namespace iceberg::rest {
+
+/// \brief Error handler interface for processing REST API error responses. 
Maps HTTP
+/// status codes to appropriate ErrorKind values following the Iceberg REST 
specification.
+class ICEBERG_REST_EXPORT ErrorHandler {
+ public:
+  virtual ~ErrorHandler() = default;
+
+  // TODO(Li Feiyang):removing ErrorModel as the inner layer and directly using
+  // ErrorResponse
+
+  /// \brief Process an error response and return an appropriate Error.
+  ///
+  /// \param error The error model parsed from the HTTP response body
+  /// \return An Error object with appropriate ErrorKind and message
+  virtual Status Accept(const ErrorModel& error) const = 0;
+};
+
+/// \brief Default error handler for REST API responses.
+class ICEBERG_REST_EXPORT DefaultErrorHandler : public ErrorHandler {
+ public:
+  /// \brief Returns the singleton instance
+  static const std::shared_ptr<DefaultErrorHandler>& Instance();
+
+  Status Accept(const ErrorModel& error) const override;
+
+ protected:
+  constexpr DefaultErrorHandler() = default;
+};
+
+/// \brief Namespace-specific error handler for create/read/update operations.
+class ICEBERG_REST_EXPORT NamespaceErrorHandler : public DefaultErrorHandler {
+ public:
+  /// \brief Returns the singleton instance
+  static const std::shared_ptr<NamespaceErrorHandler>& Instance();
+
+  Status Accept(const ErrorModel& error) const override;
+
+ protected:
+  constexpr NamespaceErrorHandler() = default;
+};
+
+/// \brief Error handler for drop namespace operations.
+class ICEBERG_REST_EXPORT DropNamespaceErrorHandler : public 
NamespaceErrorHandler {
+ public:
+  /// \brief Returns the singleton instance
+  static const std::shared_ptr<DropNamespaceErrorHandler>& Instance();
+
+  Status Accept(const ErrorModel& error) const override;
+
+ private:
+  constexpr DropNamespaceErrorHandler() = default;
+};
+
+/// \brief Table-level error handler.
+class ICEBERG_REST_EXPORT TableErrorHandler : public DefaultErrorHandler {

Review Comment:
   If we think a class will not have subclasses (I noticed that the constructor 
is set to private), then we can mark it as final. There are same modifitions 
below.



##########
src/iceberg/catalog/rest/rest_util.h:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <string>
+#include <string_view>
+#include <unordered_map>
+
+#include "iceberg/catalog/rest/iceberg_rest_export.h"
+#include "iceberg/catalog/rest/type_fwd.h"

Review Comment:
   
   ```suggestion
   ```
   ditto



-- 
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]

Reply via email to