Small update to error handling in postDemographics call

This commit is contained in:
Justin Hynes
2020-06-26 14:41:57 -04:00
parent 157f31cbc5
commit 8baccba066

View File

@@ -16,20 +16,8 @@ export async function postDemographics(userId) {
({ data } = await getAuthenticatedHttpClient()
.post(requestUrl, commitValues)
.catch((error) => {
data = {
user: userId,
gender: null,
gender_description: null,
income: null,
learner_education_level: null,
parent_education_level: null,
military_history: null,
work_status: null,
work_status_description: null,
current_work_sector: null,
future_work_sector: null,
user_ethnicity: []
}
const apiError = createDemographicsError(error);
throw apiError;
}));
return convertData(data, FROM);
@@ -88,16 +76,25 @@ export async function patchDemographics(userId, commitValues) {
({ data } = await getAuthenticatedHttpClient()
.patch(requestUrl, convertedCommitValues)
.catch((error) => {
// If there was an error making the PATCH call then we create an apiError object containing a 'demographicsError'
// fieldError. The content of the error itself isn't particularly important. This will trigger the
// `renderDemographicsServiceIssueWarningMessage()` (DemographicsSection.jsx) to display an Alert to let the
// end-user know that there may be an issue communicating with the Demographics service.
const apiError = Object.create(error);
apiError.fieldErrors = {
demographicsError: error.customAttributes.httpErrorType
}
const apiError = createDemographicsError(error);
throw apiError;
}));
return convertData(data, FROM);
}
/**
* If there was an error making the PATCH call then we create an apiError object containing a 'demographicsError'
* fieldError. The content of the error itself isn't particularly important. This will trigger the
* `renderDemographicsServiceIssueWarningMessage()` (DemographicsSection.jsx) to display an Alert to let the
* end-user know that there may be an issue communicating with the Demographics service.
*
* @param {Error} error
*/
export function createDemographicsError(error) {
const apiError = Object.create(error);
apiError.fieldErrors = {
demographicsError: error.customAttributes.httpErrorType
}
return apiError;
}