T-964120721843948: Added error handling and error messaging

This commit is contained in:
Okechi Onyeje 2019-01-09 21:00:13 -05:00
parent 82d578b279
commit 73b5900952
4 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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 });
}

View File

@ -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 });
}
}

View File

@ -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});
}