This is an automated email from the ASF dual-hosted git repository.

tyrantlucifer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new 48ab7c97d [Improve][Connector-V2][MyHours]Unified exception for 
MyHours connector (#3538)
48ab7c97d is described below

commit 48ab7c97d57b7e2d504698c583df5f8dfdef98a6
Author: TaoZex <[email protected]>
AuthorDate: Sat Nov 26 17:00:25 2022 +0800

    [Improve][Connector-V2][MyHours]Unified exception for MyHours connector 
(#3538)
    
    * [Improve][Connector-V2][MyHours]Unified exception for MyHours connector
    
    * [Feature][SeaTunnel Engine] Update code
    
    * [Improve][Connector-V2][MyHours]update header
    
    * [Improve][Connector-V2][MyHours]update Error-Quick-Reference-Manual doc
    
    * [Improve][Connector-V2][MyHours]update error code
---
 .../connector-v2/Error-Quick-Reference-Manual.md   |  6 +++
 .../seatunnel/myhours/source/MyHoursSource.java    | 17 +++++---
 .../exception/MyHoursConnectorErrorCode.java       | 48 ++++++++++++++++++++++
 .../exception/MyHoursConnectorException.java       | 35 ++++++++++++++++
 4 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/docs/en/connector-v2/Error-Quick-Reference-Manual.md 
b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
index 9fb6664b2..22b22a323 100644
--- a/docs/en/connector-v2/Error-Quick-Reference-Manual.md
+++ b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
@@ -54,6 +54,12 @@ This document records some common error codes and 
corresponding solutions of Sea
 | SLACK-01  | Conversation can not be founded in channels | When users 
encounter this error code, it means that the channel is not existed in slack 
workspace, please check it |
 | SLACK-02  | Write to slack channel failed               | When users 
encounter this error code, it means that slack has some problems, please check 
it whether is work       |
 
+## MyHours Connector Error Codes
+
+| code        | description                      | solution                    
                                                                                
             | 
+|-------------|----------------------------------|--------------------------------------------------------------------------------------------------------------------------|
+| MYHOURS-01  | Get myhours token failed         | When users encounter this 
error code, it means that login to the MyHours Failed, please check your 
network and try again |
+
 ## Rabbitmq Connector Error Codes
 
 | code        | description                                                   
| solution                                                                      
                                  |
diff --git 
a/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/MyHoursSource.java
 
b/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/MyHoursSource.java
index 473afb0f6..e6d46d1e6 100644
--- 
a/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/MyHoursSource.java
+++ 
b/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/MyHoursSource.java
@@ -18,6 +18,7 @@
 package org.apache.seatunnel.connectors.seatunnel.myhours.source;
 
 import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
 import org.apache.seatunnel.api.source.SeaTunnelSource;
 import org.apache.seatunnel.api.table.type.SeaTunnelRow;
 import org.apache.seatunnel.common.config.CheckConfigUtil;
@@ -32,6 +33,8 @@ import 
org.apache.seatunnel.connectors.seatunnel.http.source.HttpSource;
 import org.apache.seatunnel.connectors.seatunnel.http.source.HttpSourceReader;
 import 
org.apache.seatunnel.connectors.seatunnel.myhours.source.config.MyHoursSourceConfig;
 import 
org.apache.seatunnel.connectors.seatunnel.myhours.source.config.MyHoursSourceParameter;
+import 
org.apache.seatunnel.connectors.seatunnel.myhours.source.exception.MyHoursConnectorErrorCode;
+import 
org.apache.seatunnel.connectors.seatunnel.myhours.source.exception.MyHoursConnectorException;
 
 import org.apache.seatunnel.shade.com.typesafe.config.Config;
 
@@ -57,7 +60,9 @@ public class MyHoursSource extends HttpSource {
         CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig, 
MyHoursSourceConfig.URL.key(),
                 MyHoursSourceConfig.EMAIL.key(), 
MyHoursSourceConfig.PASSWORD.key());
         if (!result.isSuccess()) {
-            throw new PrepareFailException(getPluginName(), PluginType.SOURCE, 
result.getMsg());
+            throw new 
MyHoursConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    String.format("PluginName: %s, PluginType: %s, Message: 
%s",
+                            getPluginName(), PluginType.SOURCE, 
result.getMsg()));
         }
         // Login to get accessToken
         String accessToken = getAccessToken(pluginConfig);
@@ -83,11 +88,13 @@ public class MyHoursSource extends HttpSource {
                     return contentMap.get(MyHoursSourceConfig.ACCESS_TOKEN);
                 }
             }
-            throw new RuntimeException(String.format("login http client 
execute exception, http response status code:[%d], content:[%s]",
-                response.getCode(),
-                response.getContent()));
+            throw new 
MyHoursConnectorException(MyHoursConnectorErrorCode.GET_MYHOURS_TOKEN_FAILE,
+                    String.format("Login http client execute exception, http 
response status code:[%d], content:[%s]",
+                            response.getCode(),
+                            response.getContent()));
         } catch (Exception e) {
-            throw new RuntimeException("login http client execute exception");
+            throw new 
MyHoursConnectorException(MyHoursConnectorErrorCode.GET_MYHOURS_TOKEN_FAILE,
+                    "Login http client execute exception");
         } finally {
             try {
                 loginHttpClient.close();
diff --git 
a/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/exception/MyHoursConnectorErrorCode.java
 
b/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/exception/MyHoursConnectorErrorCode.java
new file mode 100644
index 000000000..49818c3e2
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/exception/MyHoursConnectorErrorCode.java
@@ -0,0 +1,48 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.myhours.source.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+
+public enum MyHoursConnectorErrorCode implements SeaTunnelErrorCode {
+    GET_MYHOURS_TOKEN_FAILE("MYHOURS-01",  "Get myhours token failed");
+
+    private final String code;
+
+    private final String description;
+
+    MyHoursConnectorErrorCode(String code, String description) {
+        this.code = code;
+        this.description = description;
+    }
+
+    @Override
+    public String getCode() {
+        return this.code;
+    }
+
+    @Override
+    public String getDescription() {
+        return this.description;
+    }
+
+    @Override
+    public String getErrorMessage() {
+        return SeaTunnelErrorCode.super.getErrorMessage();
+    }
+}
diff --git 
a/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/exception/MyHoursConnectorException.java
 
b/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/exception/MyHoursConnectorException.java
new file mode 100644
index 000000000..a67b3d0ab
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/exception/MyHoursConnectorException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.myhours.source.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class MyHoursConnectorException extends SeaTunnelRuntimeException {
+    public MyHoursConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, 
String errorMessage) {
+        super(seaTunnelErrorCode, errorMessage);
+    }
+
+    public MyHoursConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, 
String errorMessage, Throwable cause) {
+        super(seaTunnelErrorCode, errorMessage, cause);
+    }
+
+    public MyHoursConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, 
Throwable cause) {
+        super(seaTunnelErrorCode, cause);
+    }
+}

Reply via email to