Skip to content

Commit

Permalink
PB-984: avoid duplicate errors
Browse files Browse the repository at this point in the history
Issue : sometimes, errors and warning might get added multiple times, and as they are new object instances, the set had issue ensuring unicity

Fix : we filter the errors and warnings received, ensuring we only add messages with a different message AND different parameters.
  • Loading branch information
ltkum committed Oct 8, 2024
1 parent d112526 commit 363f179
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/store/modules/ui.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,24 @@ export default {
setShowDisclaimer({ commit }, { showDisclaimer, dispatcher }) {
commit('setShowDisclaimer', { showDisclaimer, dispatcher })
},
addErrors({ commit }, { errors, dispatcher }) {
addErrors({ commit, state }, { errors, dispatcher }) {
if (
errors instanceof Array &&
errors.filter((error) => error instanceof ErrorMessage).length === errors.length
) {
commit('addErrors', { errors, dispatcher })
errors = errors.filter((error) => {
// we only add the errors that are not existing within the store
return (
state.errors.filter((otherError) => {
otherError instanceof ErrorMessage &&
otherError.msg === error.msg &&
otherError.params === error.params
}).length === 0
)
})
if (errors.length > 0) {
commit('addErrors', { errors, dispatcher })
}
} else {
throw new Error(
`Error ${errors} dispatched by ${dispatcher} is not of type ErrorMessage, or not an Array of ErrorMessages`
Expand All @@ -412,13 +424,25 @@ export default {
commit('removeError', { error, dispatcher })
}
},
addWarnings({ commit }, { warnings, dispatcher }) {
addWarnings({ commit, state }, { warnings, dispatcher }) {
if (
warnings instanceof Array &&
warnings.filter((warning) => warning instanceof WarningMessage).length ===
warnings.length
) {
commit('addWarnings', { warnings, dispatcher })
warnings = warnings.filter((warning) => {
// we only add the warnings that are not existing within the store
return (
state.warnings.filter((otherWarning) => {
otherWarning instanceof WarningMessage &&
otherWarning.msg === warning.msg &&
otherWarning.params === warning.params
}).length === 0
)
})
if (warnings.length > 0) {
commit('addWarnings', { warnings, dispatcher })
}
} else {
throw new Error(
`Warning ${warnings} dispatched by ${dispatcher} is not of type WarningMessage, or not an Array of WarningMessages`
Expand Down

0 comments on commit 363f179

Please sign in to comment.