bryanck commented on code in PR #5698:
URL: https://github.com/apache/iceberg/pull/5698#discussion_r973594276


##########
core/src/main/java/org/apache/iceberg/rest/responses/OAuthErrorResponseParser.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.responses;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UncheckedIOException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.JsonUtil;
+
+public class OAuthErrorResponseParser {
+
+  private OAuthErrorResponseParser() {}
+
+  private static final String ERROR = "error";
+  private static final String ERROR_DESCRIPTION = "error_description";
+  private static final String ERROR_URI = "error_uri";
+
+  public static String toJson(OAuthErrorResponse errorResponse) {
+    return toJson(errorResponse, false);
+  }
+
+  public static String toJson(OAuthErrorResponse errorResponse, boolean 
pretty) {
+    try {
+      StringWriter writer = new StringWriter();
+      JsonGenerator generator = JsonUtil.factory().createGenerator(writer);
+      if (pretty) {
+        generator.useDefaultPrettyPrinter();
+      }
+      toJson(errorResponse, generator);
+      generator.flush();
+      return writer.toString();
+    } catch (IOException e) {
+      throw new UncheckedIOException(
+          String.format("Failed to write error response json for: %s", 
errorResponse), e);
+    }
+  }
+
+  public static void toJson(OAuthErrorResponse errorResponse, JsonGenerator 
generator)
+      throws IOException {
+    generator.writeStartObject();
+
+    generator.writeStringField(ERROR, errorResponse.error());
+    generator.writeStringField(ERROR_DESCRIPTION, 
errorResponse.errorDescription());
+    generator.writeStringField(ERROR_URI, errorResponse.errorUri());
+
+    generator.writeEndObject();
+  }
+
+  /**
+   * Read OAuthErrorResponse from a JSON string.
+   *
+   * @param json a JSON string of an OAuthErrorResponse
+   * @return an OAuthErrorResponse object
+   */
+  public static OAuthErrorResponse fromJson(String json) {
+    try {
+      return fromJson(JsonUtil.mapper().readValue(json, JsonNode.class));
+    } catch (IOException e) {
+      throw new UncheckedIOException("Failed to read JSON string: " + json, e);
+    }
+  }
+
+  public static OAuthErrorResponse fromJson(JsonNode jsonNode) {
+    Preconditions.checkArgument(
+        jsonNode != null && jsonNode.isObject(),
+        "Cannot parse error response from non-object value: %s",
+        jsonNode);
+    Preconditions.checkArgument(jsonNode.has(ERROR), "Cannot parse missing 
field: error");

Review Comment:
   I removed this (also in ErrorResponseParser)



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