Skip to content

Commit

Permalink
Guard against null param in util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-marcellini committed Aug 29, 2022
1 parent d9b01d4 commit 66c3c60
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ import ONYXKEYS from '../ONYXKEYS';
* Checks if we have any errors stored within the POLICY_MEMBER_LIST. Determines whether we should show a red brick road error or not.
* Data structure: {email: {role:'user', errors: []}, email2: {role:'admin', errors: [{1231312313: 'Unable to do X'}]}, ...}
*
* @param {Object} policyMemberList
* @param {Object} [policyMemberList]
* @returns {Boolean}
*/
function hasPolicyMemberError(policyMemberList) {
if (!policyMemberList) {
return false;
}
return _.some(policyMemberList, member => !_.isEmpty(member.errors));
}

/**
* Check if the policy has any errors, and if it doesn't, then check if it has any error fields.
*
* @param {Object} policy
* @param {Object} [policy]
* @param {Object} policy.errors
* @param {Object} policy.errorFields
* @return {Boolean}
*/
function hasPolicyError(policy) {
if (!policy) {
return false;
}
return !_.isEmpty(policy.errors)
? true
: _.some(policy.errorFields, fieldErrors => !_.isEmpty(fieldErrors));
Expand All @@ -31,10 +37,13 @@ function hasPolicyError(policy) {
/**
* Checks if we have any errors stored within the policy custom units.
*
* @param {Object} policy
* @param {Object} [policy]
* @returns {Boolean}
*/
function hasCustomUnitsError(policy) {
if (!policy) {
return false;
}
return !_.isEmpty(_.pick(policy.customUnits, 'errors'));
}

Expand Down

0 comments on commit 66c3c60

Please sign in to comment.