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

liugddx 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 0a0956251 [Improve][Connector-V2][DingTalk] Unified exception for 
dingtalk sink connector (#3678)
0a0956251 is described below

commit 0a095625159dd5cf106637ff5d47f1e3615ba867
Author: Tyrantlucifer <[email protected]>
AuthorDate: Thu Dec 8 16:06:56 2022 +0800

    [Improve][Connector-V2][DingTalk] Unified exception for dingtalk sink 
connector (#3678)
---
 .../connector-v2/Error-Quick-Reference-Manual.md   | 32 +++++++------
 .../exception/DingTalkConnectorErrorCode.java      | 53 ++++++++++++++++++++++
 .../exception/DingTalkConnectorException.java      | 35 ++++++++++++++
 .../connectors/seatunnel/sink/DingTalkSink.java    | 11 +++--
 .../connectors/seatunnel/sink/DingTalkWriter.java  |  8 +++-
 5 files changed, 119 insertions(+), 20 deletions(-)

diff --git a/docs/en/connector-v2/Error-Quick-Reference-Manual.md 
b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
index bd42c3f66..190e64465 100644
--- a/docs/en/connector-v2/Error-Quick-Reference-Manual.md
+++ b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
@@ -171,7 +171,6 @@ problems encountered by users.
 | CLICKHOUSE-05 | Get cluster list from clickhouse failed                      
             | When users encounter this error code, it means that the 
clickhouse cluster is not configured correctly, please check                    
                                |
 | CLICKHOUSE-06 | Shard key not found in table                                 
             | When users encounter this error code, it means that the shard 
key of the distributed table is not configured, please check                    
                          |
 
-
 ## Jdbc Connector Error Codes
 
 | code    | description                                                        
 | solution                                                                     
                                                                                
                                               |
@@ -185,18 +184,25 @@ problems encountered by users.
 
 ## Pulsar Connector Error Codes
 
-| code         | description                                                  
| solution                                                                      
                                                                                
        |
-|--------------|--------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| PULSAR-01 | Open pulsar admin failed                                        
| When users encounter this error code, it means that open pulsar admin failed, 
please check it                                        |
-| PULSAR-02 | Open pulsar client failed                                       
| When users encounter this error code, it means that open pulsar client 
failed, please check it                                       |
-| PULSAR-03 | Pulsar authentication failed                                    
| When users encounter this error code, it means that Pulsar Authentication 
failed, please check it                                    |
-| PULSAR-04 | Subscribe topic from pulsar failed                              
| When users encounter this error code, it means that Subscribe topic from 
pulsar failed, please check it                              |
-| PULSAR-05 | Get last cursor of pulsar topic failed                          
| When users encounter this error code, it means that get last cursor of pulsar 
topic failed, please check it                          |
-| PULSAR-06 | Get partition information of pulsar topic failed                
| When users encounter this error code, it means that Get partition information 
of pulsar topic failed, please check it                |
+| code      | description                                      | solution      
                                                                                
                        |
+|-----------|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
+| PULSAR-01 | Open pulsar admin failed                         | When users 
encounter this error code, it means that open pulsar admin failed, please check 
it                         |
+| PULSAR-02 | Open pulsar client failed                        | When users 
encounter this error code, it means that open pulsar client failed, please 
check it                        |
+| PULSAR-03 | Pulsar authentication failed                     | When users 
encounter this error code, it means that Pulsar Authentication failed, please 
check it                     |
+| PULSAR-04 | Subscribe topic from pulsar failed               | When users 
encounter this error code, it means that Subscribe topic from pulsar failed, 
please check it               |
+| PULSAR-05 | Get last cursor of pulsar topic failed           | When users 
encounter this error code, it means that get last cursor of pulsar topic 
failed, please check it           |
+| PULSAR-06 | Get partition information of pulsar topic failed | When users 
encounter this error code, it means that Get partition information of pulsar 
topic failed, please check it |
 
 ## StarRocks Connector Error Codes
 
-| code    | description                 | solution                             
                                                                                
                                            |
-|---------|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| STARROCKS-01 | Flush batch data to sink connector failed        | When users 
encounter this error code, it means that flush batch data to sink connector 
failed, please check it                                          |
-| STARROCKS-02 | Writing records to StarRocks failed. | When users encounter 
this error code, it means that writing records to StarRocks failed, please 
check data from files whether is correct |
+| code         | description                               | solution          
                                                                                
                                       |
+|--------------|-------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
+| STARROCKS-01 | Flush batch data to sink connector failed | When users 
encounter this error code, it means that flush batch data to sink connector 
failed, please check it                           |
+| STARROCKS-02 | Writing records to StarRocks failed      | When users 
encounter this error code, it means that writing records to StarRocks failed, 
please check data from files whether is correct |
+
+## DingTalk Connector Error Codes
+
+| code        | description                             | solution             
                                                                                
                |
+|-------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------|
+| DINGTALK-01 | Send response to DinkTalk server failed | When users encounter 
this error code, it means that send response message to DinkTalk server failed, 
please check it |
+| DINGTALK-02 | Get sign from DinkTalk server failed    | When users encounter 
this error code, it means that get signature from DinkTalk server failed , 
please check it      |
diff --git 
a/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/exception/DingTalkConnectorErrorCode.java
 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/exception/DingTalkConnectorErrorCode.java
new file mode 100644
index 000000000..e3ecebbac
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/exception/DingTalkConnectorErrorCode.java
@@ -0,0 +1,53 @@
+/*
+ * 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.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+
+public enum DingTalkConnectorErrorCode implements SeaTunnelErrorCode {
+    SEND_RESPONSE_FAILED("DINGTALK-01", "Send response to DinkTalk server 
failed"),
+    GET_SIGN_FAILED("DINGTALK-02", "Get sign from DinkTalk server failed");
+
+    private final String code;
+    private final String description;
+
+    DingTalkConnectorErrorCode(String code, String description) {
+        this.code = code;
+        this.description = description;
+    }
+
+    /**
+     * Get error code
+     *
+     * @return error code
+     */
+    @Override
+    public String getCode() {
+        return code;
+    }
+
+    /**
+     * Get error description
+     *
+     * @return error description
+     */
+    @Override
+    public String getDescription() {
+        return description;
+    }
+}
diff --git 
a/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/exception/DingTalkConnectorException.java
 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/exception/DingTalkConnectorException.java
new file mode 100644
index 000000000..e3db289c8
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/exception/DingTalkConnectorException.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.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class DingTalkConnectorException extends SeaTunnelRuntimeException {
+    public DingTalkConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, 
String errorMessage) {
+        super(seaTunnelErrorCode, errorMessage);
+    }
+
+    public DingTalkConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, 
String errorMessage, Throwable cause) {
+        super(seaTunnelErrorCode, errorMessage, cause);
+    }
+
+    public DingTalkConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, 
Throwable cause) {
+        super(seaTunnelErrorCode, cause);
+    }
+}
diff --git 
a/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkSink.java
 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkSink.java
index 27252b3b4..40feb05b0 100644
--- 
a/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkSink.java
+++ 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkSink.java
@@ -21,14 +21,15 @@ import static 
org.apache.seatunnel.connectors.seatunnel.config.DingTalkConfig.SE
 import static 
org.apache.seatunnel.connectors.seatunnel.config.DingTalkConfig.URL;
 
 import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
 import org.apache.seatunnel.api.sink.SeaTunnelSink;
 import org.apache.seatunnel.api.sink.SinkWriter.Context;
 import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
 import org.apache.seatunnel.api.table.type.SeaTunnelRow;
 import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
-import org.apache.seatunnel.common.constants.PluginType;
 import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
 import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import 
org.apache.seatunnel.connectors.seatunnel.exception.DingTalkConnectorException;
 
 import org.apache.seatunnel.shade.com.typesafe.config.Config;
 
@@ -54,12 +55,12 @@ public class DingTalkSink extends 
AbstractSimpleSink<SeaTunnelRow, Void> {
     @Override
     public void prepare(Config pluginConfig) throws PrepareFailException {
         if (pluginConfig.getIsNull(URL.key())) {
-            throw new PrepareFailException(getPluginName(), PluginType.SINK,
-                String.format("Config must include column : %s", URL.key()));
+            throw new 
DingTalkConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    String.format("Config must include column : %s", 
URL.key()));
         }
         if (pluginConfig.getIsNull(SECRET.key())) {
-            throw new PrepareFailException(getPluginName(), PluginType.SINK,
-                String.format("Config must include column : %s", 
SECRET.key()));
+            throw new 
DingTalkConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    String.format("Config must include column : %s", 
SECRET.key()));
         }
         this.pluginConfig = pluginConfig;
     }
diff --git 
a/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkWriter.java
 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkWriter.java
index ab2b3468c..36ce7ead7 100644
--- 
a/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkWriter.java
+++ 
b/seatunnel-connectors-v2/connector-dingtalk/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DingTalkWriter.java
@@ -19,6 +19,8 @@ package org.apache.seatunnel.connectors.seatunnel.sink;
 
 import org.apache.seatunnel.api.table.type.SeaTunnelRow;
 import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import 
org.apache.seatunnel.connectors.seatunnel.exception.DingTalkConnectorErrorCode;
+import 
org.apache.seatunnel.connectors.seatunnel.exception.DingTalkConnectorException;
 
 import com.dingtalk.api.DefaultDingTalkClient;
 import com.dingtalk.api.request.OapiRobotSendRequest;
@@ -80,7 +82,8 @@ public class DingTalkWriter extends 
AbstractSinkWriter<SeaTunnelRow, Void> {
             try {
                 return this.client.execute(request);
             } catch (ApiException e) {
-                throw new IOException(e);
+                throw new 
DingTalkConnectorException(DingTalkConnectorErrorCode.SEND_RESPONSE_FAILED,
+                        "Send response message to DinkTalk server failed", e);
             }
         }
 
@@ -98,7 +101,8 @@ public class DingTalkWriter extends 
AbstractSinkWriter<SeaTunnelRow, Void> {
                 byte[] signData = 
mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
                 return 
URLEncoder.encode(Base64.getEncoder().encodeToString(signData), "UTF-8");
             } catch (Exception e) {
-                throw new IOException(e);
+                throw new 
DingTalkConnectorException(DingTalkConnectorErrorCode.GET_SIGN_FAILED,
+                        "Get signature from DinkTalk server failed", e);
             }
         }
     }

Reply via email to