Merge pull request #221 from edx/tuchfarber/catch_403_for_inactive_user

Catch 403 for inactive user on coaching API
This commit is contained in:
Matt Tuchfarber
2020-05-05 11:35:00 -04:00
committed by GitHub

View File

@@ -8,8 +8,20 @@ import get from 'lodash.get';
* @param {Number} userId users are identified in the api by LMS id
*/
export async function getCoachingPreferences(userId) {
const { data } = await getAuthenticatedHttpClient()
.get(`${getConfig().LMS_BASE_URL}/api/coaching/v1/users/${userId}/`);
let data = {};
try {
data = await getAuthenticatedHttpClient()
.get(`${getConfig().LMS_BASE_URL}/api/coaching/v1/users/${userId}/`);
} catch (error) {
// If a user isn't active the API call will fail with a lack of credentials.
data = {
coaching_consent: false,
user: userId,
eligible_for_coaching: false,
consent_form_seen: false,
};
}
return data;
}