This is an automated email from the ASF dual-hosted git repository.
wanghailin 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 829261e1a [Improve][Connector-V2][Email] Unified exception for email
connector (#3898)
829261e1a is described below
commit 829261e1a655bf3fb1867d842323e5b3374e1178
Author: Tyrantlucifer <[email protected]>
AuthorDate: Wed Jan 11 21:38:59 2023 +0800
[Improve][Connector-V2][Email] Unified exception for email connector (#3898)
* [Feature][Connector-V2][Email] Unified exception
---
.../connector-v2/Error-Quick-Reference-Manual.md | 6 ++++
.../email/exception/EmailConnectorErrorCode.java | 42 ++++++++++++++++++++++
.../email/exception/EmailConnectorException.java | 35 ++++++++++++++++++
.../seatunnel/email/sink/EmailSinkWriter.java | 18 +++++-----
4 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/docs/en/connector-v2/Error-Quick-Reference-Manual.md
b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
index 1a3a65558..b684779b9 100644
--- a/docs/en/connector-v2/Error-Quick-Reference-Manual.md
+++ b/docs/en/connector-v2/Error-Quick-Reference-Manual.md
@@ -205,3 +205,9 @@ problems encountered by users.
|-------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| 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 |
+
+## Email Connector Error Codes
+
+| code | description | solution
|
+|-------------|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| EMAIL-01 | Send email failed | When users encounter this error code, it
means that send email to target server failed, please adjust the network
environment according to the abnormal information |
diff --git
a/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/exception/EmailConnectorErrorCode.java
b/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/exception/EmailConnectorErrorCode.java
new file mode 100644
index 000000000..1a3ef80f2
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/exception/EmailConnectorErrorCode.java
@@ -0,0 +1,42 @@
+/*
+ * 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.email.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+
+public enum EmailConnectorErrorCode implements SeaTunnelErrorCode {
+ SEND_EMAIL_FAILED("EMAIL-01", "Send email failed");
+
+ private final String code;
+ private final String description;
+
+ EmailConnectorErrorCode(String code, String description) {
+ this.code = code;
+ this.description = description;
+ }
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+}
diff --git
a/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/exception/EmailConnectorException.java
b/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/exception/EmailConnectorException.java
new file mode 100644
index 000000000..d9c40b45c
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/exception/EmailConnectorException.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.email.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class EmailConnectorException extends SeaTunnelRuntimeException {
+ public EmailConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
String errorMessage) {
+ super(seaTunnelErrorCode, errorMessage);
+ }
+
+ public EmailConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
String errorMessage, Throwable cause) {
+ super(seaTunnelErrorCode, errorMessage, cause);
+ }
+
+ public EmailConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
Throwable cause) {
+ super(seaTunnelErrorCode, cause);
+ }
+}
diff --git
a/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/sink/EmailSinkWriter.java
b/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/sink/EmailSinkWriter.java
index 2832b7d40..020be1a78 100644
---
a/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/sink/EmailSinkWriter.java
+++
b/seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/sink/EmailSinkWriter.java
@@ -19,8 +19,11 @@ package org.apache.seatunnel.connectors.seatunnel.email.sink;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
import
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
import org.apache.seatunnel.connectors.seatunnel.email.config.EmailSinkConfig;
+import
org.apache.seatunnel.connectors.seatunnel.email.exception.EmailConnectorErrorCode;
+import
org.apache.seatunnel.connectors.seatunnel.email.exception.EmailConnectorException;
import org.apache.seatunnel.shade.com.typesafe.config.Config;
@@ -130,8 +133,7 @@ public class EmailSinkWriter extends
AbstractSinkWriter<SeaTunnelRow, Void> {
Transport.send(message);
log.info("Sent message successfully....");
} catch (Exception e) {
- log.warn("send email Fail.", e);
- throw new RuntimeException("send email Fail.", e);
+ throw new
EmailConnectorException(EmailConnectorErrorCode.SEND_EMAIL_FAILED, "Send email
failed", e);
}
}
@@ -139,18 +141,16 @@ public class EmailSinkWriter extends
AbstractSinkWriter<SeaTunnelRow, Void> {
try {
String data = stringBuffer.toString();
File file = new File("emailsink.csv");
- //if file doesnt exists, then create it
+ // if file doesn't exist, then create it
if (!file.exists()) {
file.createNewFile();
}
- FileWriter fileWritter = new FileWriter(file.getName());
- fileWritter.write(data);
- fileWritter.close();
+ FileWriter fileWriter = new FileWriter(file.getName());
+ fileWriter.write(data);
+ fileWriter.close();
log.info("Create File successfully....");
} catch (IOException e) {
- log.warn("Create File Fail.", e);
- throw new RuntimeException("Create File Fail.", e);
+ throw new
EmailConnectorException(CommonErrorCode.FILE_OPERATION_FAILED, "Create file
failed", e);
}
-
}
}