From 73b59009528958de8f7302ffbd98beadb8455988 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Wed, 9 Jan 2019 21:00:13 -0500 Subject: [PATCH] T-964120721843948: Added error handling and error messaging --- src/config/errors.js | 2 +- src/ups/auth/handlers.js | 2 ++ src/ups/profiles/handlers.js | 6 +++--- src/ups/socials/linkedIn.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/config/errors.js b/src/config/errors.js index 55378b9..1a10f2e 100644 --- a/src/config/errors.js +++ b/src/config/errors.js @@ -19,10 +19,10 @@ module.exports = { APP_NETWORK_TIMEOUT: 'app/network-timeout', APP_UNABLE_TO_PARSE_RESPONSE: 'app/unable-to-parse-response', APP_FIREBASE_DATABASE_ERROR: 'app/firebase-database-error', - AUTH_LINKEDIN_REQUEST_HTML_FAILURE: 'auth/linkedin-request-html-failure', AUTH_LINKEDIN_REQUEST_TOKEN_FAILURE: 'auth/linkedin-request-token-failure', AUTH_LINKEDIN_ACCESS_TOKEN_FAILURE: 'auth/linkedin-access-token-failure', AUTH_LINKEDIN_PROFILE_REQUEST_FAILURE: 'auth/linkedin-profile-request-failure', + AUTH_LINKEDIN_TOKEN_SCOPE_INVALID_REQUEST_FAILURE: 'auth/linkedin-token-scope-invalid-request-failure', //Request Errors MISSING_BODY_ATTRIBUTES: 'request/missing-body-attributes', //Profile Errors diff --git a/src/ups/auth/handlers.js b/src/ups/auth/handlers.js index 5c2dce9..243148c 100644 --- a/src/ups/auth/handlers.js +++ b/src/ups/auth/handlers.js @@ -183,6 +183,8 @@ function getLinkedInAccessToken(req, res) { const token = req.query.code; if (token) { linkedin.getOAuthAccessToken(token, (result) => res.send(result)); + } else if (req.query.error) { + res.status(http.UNAUTHORIZED).json({ error: errors.AUTH_LINKEDIN_TOKEN_SCOPE_INVALID_REQUEST_FAILURE}); } else { res.status(http.UNAUTHORIZED).json({ error: errors.AUTH_LINKEDIN_REQUEST_TOKEN_FAILURE }); } diff --git a/src/ups/profiles/handlers.js b/src/ups/profiles/handlers.js index 6085056..c82d183 100644 --- a/src/ups/profiles/handlers.js +++ b/src/ups/profiles/handlers.js @@ -41,12 +41,12 @@ async function getUserProfile(req, res) { try { const tagferId = authDao.getSession(sessionId).tagferId; profileDao.getProfile(profileNumber,tagferId).then((profile) => { - res.status(http.OK).json({profile}) + res.status(http.OK).json({profile}); }).catch(error => { - res.status(http.INTERNAL_SERVER_ERROR).json({error: error.code}) + res.status(http.INTERNAL_SERVER_ERROR).json({error: error.code}); }) } catch (error) { - res.status(http.UNAUTHORIZED).json({ error }) + res.status(http.UNAUTHORIZED).json({ error }); } } diff --git a/src/ups/socials/linkedIn.js b/src/ups/socials/linkedIn.js index 3b928b2..d381d2c 100644 --- a/src/ups/socials/linkedIn.js +++ b/src/ups/socials/linkedIn.js @@ -13,7 +13,7 @@ const _ = require('lodash'); function getOAuthLoginURL(callback) { let linkedIn = appConfig.keys.linkedIn; let linkedInRequest = _.cloneDeep(linkedIn.endpoints.request_token); - linkedInRequest.url = `${linkedInRequest.url}?client_id=${linkedIn.consumer.key}&scope=r_fullprofile%20r_basicprofile%20r_emailaddress&redirect_uri=${encodeURIComponent(linkedIn.redirect_uri)}&response_type=code`; + linkedInRequest.url = `${linkedInRequest.url}?client_id=${linkedIn.consumer.key}&scope=r_basicprofile%20r_emailaddress&redirect_uri=${encodeURIComponent(linkedIn.redirect_uri)}&response_type=code`; callback({ uri: linkedInRequest.url}); }