From 2cc3c9136189937e3eb45d1dccab6088094ef011 Mon Sep 17 00:00:00 2001 From: counter Date: Sat, 14 Jan 2023 10:43:46 -0800 Subject: [PATCH] adding error handling --- app.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 88d81ca..a21cd16 100644 --- a/app.js +++ b/app.js @@ -284,12 +284,18 @@ async function get_app_server() { }); app.get('/oauth-login', async (req, res) => { - const code = req.query.code; - const {tokens} = await client.getToken(code); - client.setCredentials(tokens); - const oauth2 = google.oauth2({version: 'v1', auth: client}); - const email = await oauth2.userinfo.v2.me.get(); - res.send(`Hello ${email.data.email}!`); + try{ + const code = req.query.code; + const {tokens} = await client.getToken(code); + client.setCredentials(tokens); + const oauth2 = google.oauth2({version: 'v1', auth: client}); + const email = await oauth2.userinfo.v2.me.get(); + res.send(`Hello ${email.data.email}!`); + + } catch (error) { + console.log(`Error Occured: ${error}`); + res.status(500).send("Error Occured"); + } });