zhjwpku commented on code in PR #763:
URL: https://github.com/apache/iceberg-cpp/pull/763#discussion_r3450245019


##########
src/iceberg/catalog/rest/http_client.cc:
##########
@@ -151,13 +154,34 @@ Result<ErrorResponse> TryParseErrorResponse(const 
std::string& text) {
   return error_result;
 }
 
+/// \brief Tries to parse the response body as an OAuth error response.
+Result<ErrorResponse> TryParseOAuthErrorResponse(uint32_t code, const 
std::string& text) {
+  if (text.empty()) {
+    return InvalidArgument("Empty response body");
+  }
+
+  ICEBERG_ASSIGN_OR_RAISE(auto json_result, FromJsonString(text));
+
+  ErrorResponse error;
+  error.code = code;
+  ICEBERG_ASSIGN_OR_RAISE(error.type,
+                          GetJsonValue<std::string>(json_result, kOAuthError));
+  ICEBERG_ASSIGN_OR_RAISE(error.message, GetJsonValueOrDefault<std::string>(
+                                             json_result, 
kOAuthErrorDescription));
+  return error;
+}
+
 /// \brief Handles failure responses by invoking the provided error handler.
 Status HandleFailureResponse(const cpr::Response& response,
                              const ErrorHandler& error_handler) {
   if (IsSuccessful(response.status_code)) {
     return {};
   }
-  auto parse_result = TryParseErrorResponse(response.text);
+  auto parse_result =
+      dynamic_cast<const OAuthErrorHandler*>(&error_handler) != nullptr

Review Comment:
   This looks a bit ugly. Maybe we should add a `parseResponse` interface to 
`ErrorHandler`, similar to the Java impl.
   
   @wgtmac WDYT?



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