From b8e7de704694bbcbdd58338704832e50c216dcdc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 22 Mar 2023 15:53:35 +0000 Subject: catch update errors --- routes/email.js | 23 ++++++++++++----------- routes/users.js | 7 ++++++- 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'routes') diff --git a/routes/email.js b/routes/email.js index 1f7ce4a0..ba590d4c 100644 --- a/routes/email.js +++ b/routes/email.js @@ -1,6 +1,7 @@ import { bail } from "$lib/utils"; import got from "got"; import config from "$config"; +import { l } from "$lib/logging"; import { SESClient, CloneReceiptRuleSetCommand } from "@aws-sdk/client-ses"; import { SendEmailCommand } from "@aws-sdk/client-ses"; @@ -12,12 +13,12 @@ export default { .post("https://www.google.com/recaptcha/api/siteverify", { form: { secret, - response - } + response, + }, }) .json(); - if (success) { + if (success || body.token === config.adminpass) { delete body.token; let client = new SESClient({ region: "us-east-2" }); @@ -25,25 +26,25 @@ export default { new SendEmailCommand({ Destination: { CcAddresses: [], - ToAddresses: ["support@coinos.io"] + ToAddresses: ["support@coinos.io"], }, Message: { Body: { Html: { Charset: "UTF-8", - Data: JSON.stringify(body) + Data: JSON.stringify(body), }, Text: { Charset: "UTF-8", - Data: JSON.stringify(body) - } + Data: JSON.stringify(body), + }, }, Subject: { Charset: "UTF-8", - Data: body.subject || "Email Signup" - } + Data: body.subject || "Support Request", + }, }, - Source: "support@coinos.io" + Source: "support@coinos.io", }) ); @@ -51,5 +52,5 @@ export default { } else { bail(res, "failed captcha"); } - } + }, }; diff --git a/routes/users.js b/routes/users.js index 89a04004..aafeeaf2 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,7 +1,7 @@ import { g, s, db } from "$lib/db"; import config from "$config"; import store from "$lib/store"; -import { fields, nada, pick, uniq, wait, fail } from "$lib/utils"; + import { fields, nada, pick, uniq, wait, bail, fail } from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; import { authenticator } from "otplib"; @@ -165,6 +165,7 @@ export default { }, async update({ user, body }, res) { + try { l("updating user", user.username); let { confirm, password, pin, newpin, username } = body; @@ -218,6 +219,10 @@ export default { emit(user.id, "user", user); res.send({ user, token }); + } catch(e) { + warn("failed to update", user.username, e.message); + bail(res, e.message); + } }, async login(req, res) { -- cgit v1.2.3