myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 727c655cc73ce9fd809b4ce0e35d26010026e6fc
parent 460fadf96f8827ea3a5fb9bf95e0599feff4ab90
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Wed, 18 Sep 2024 22:01:03 +0200

feat(magic): improve error handling

Diffstat:
Msrc/api/server.cjs | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/api/server.cjs b/src/api/server.cjs @@ -39,6 +39,7 @@ if (jwt_secret === undefined) { } // configure mail transport +// https://nodemailer.com/smtp const transport = nodemailer.createTransport({ host: process.env.SMTP_HOST, port: process.env.SMTP_PORT, @@ -112,7 +113,7 @@ const server = http.createServer(async (req, res) => { data: user, })); } else { - throw {message: "Token signature invalid"} + throw new Error("Token signature invalid") } } catch (error) { serverError(res, error); @@ -141,14 +142,14 @@ const server = http.createServer(async (req, res) => { const b = Buffer.concat(body); try { if (b.length < 1) { - throw {message: "Empty request body"} + throw new Error("Empty request body") } input = JSON.parse(b); console.log(' Link request for:', input.email); const users = await getUser(input.email); if (users.length < 1) { - throw {message: "User not found"} + throw new Error("User not found") } const user = users[0] @@ -215,7 +216,7 @@ async function invalidateToken(token) { return users } catch (error) { console.log('Error occurred in invalidateToken:', error); - throw error + throw error.errors[0] } } @@ -228,7 +229,7 @@ async function lookupToken(token) { return users } catch (error) { console.log('Error occurred in lookupToken:', error); - throw error + throw error.errors[0] } } @@ -243,7 +244,7 @@ async function saveToken(id, token, exp) { return users } catch (error) { console.log('Error occurred in saveToken:', error); - throw error + throw error.errors[0] } } @@ -264,7 +265,7 @@ async function getUser(email) { return users } catch (error) { console.log('Error occurred in getUser:', error); - throw error + throw error.errors[0] } }