From ae7db41acb17cdae6706c78c026f4715fa717d62 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Sat, 29 Feb 2020 23:13:30 +0100 Subject: [PATCH] main: try catch block --- main.js | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/main.js b/main.js index 8464cb7f..46e688a3 100644 --- a/main.js +++ b/main.js @@ -12,35 +12,39 @@ function get_body(body) { } async function main() { - server_address = core.getInput("server_address", {required: true}) - server_port = core.getInput("server_port", {required: true}) - username = core.getInput("username", {required: true}) - password = core.getInput("password", {required: true}) - subject = core.getInput("subject", {required: true}) - body = core.getInput("body", {required: true}) - to = core.getInput("to", {required: true}) - from = core.getInput("from", {required: true}) - html = core.getInput("html") || "false" + try { + server_address = core.getInput("server_address", { required: true }) + server_port = core.getInput("server_port", { required: true }) + username = core.getInput("username", { required: true }) + password = core.getInput("password", { required: true }) + subject = core.getInput("subject", { required: true }) + body = core.getInput("body", { required: true }) + to = core.getInput("to", { required: true }) + from = core.getInput("from", { required: true }) + html = core.getInput("html") || "false" - transport = nodemailer.createTransport({ - host: server_address, - port: server_port, - secure: server_port == "465", - auth: { - user: username, - pass: password, - } - }) + transport = nodemailer.createTransport({ + host: server_address, + port: server_port, + secure: server_port == "465", + auth: { + user: username, + pass: password, + } + }) - info = await transport.sendMail({ - from: `"${from}" <${username}>`, - to: to, - subject: subject, - text: html == "false" ? get_body(body) : undefined, - html: html == "true" ? get_body(body) : undefined, - }) + info = await transport.sendMail({ + from: `"${from}" <${username}>`, + to: to, + subject: subject, + text: html == "false" ? get_body(body) : undefined, + html: html == "true" ? get_body(body) : undefined, + }) - console.log(info) + console.log(info) + } catch (error) { + core.setFailed(error.message) + } } main() \ No newline at end of file