Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-984: avoid duplicate errors #1092

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/store/modules/ui.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,18 @@ export default {
setShowDisclaimer({ commit }, { showDisclaimer, dispatcher }) {
commit('setShowDisclaimer', { showDisclaimer, dispatcher })
},
addErrors({ commit }, { errors, dispatcher }) {
if (
errors instanceof Array &&
errors.filter((error) => error instanceof ErrorMessage).length === errors.length
) {
commit('addErrors', { errors, dispatcher })
addErrors({ commit, state }, { errors, dispatcher }) {
if (errors instanceof Array && errors.every((error) => error instanceof ErrorMessage)) {
errors = errors.filter(
(error) =>
// we only add the errors that are not existing within the store
![...state.errors].some((otherError) => {
error.isEquals(otherError)
})
)
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 +418,22 @@ 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
warnings.every((warning) => warning instanceof WarningMessage)
) {
commit('addWarnings', { warnings, dispatcher })
warnings = warnings.filter(
(warning) =>
// we only add the warnings that are not existing within the store
![...state.warnings].some((otherWarning) => {
warning.isEquals(otherWarning)
})
)
log.error(warnings)
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
11 changes: 10 additions & 1 deletion src/utils/ErrorMessage.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ export default class ErrorMessage {
*/
constructor(msg, params = null) {
this.msg = msg
this.params = params
this.params = params ?? {}
}

isEquals(object) {
return (
object instanceof ErrorMessage &&
object.msg === this.msg &&
Object.keys(this.params).length === Object.keys(object.params).length &&
Object.keys(this.params).every((key) => this.params[key] === object.params[key])
)
}
}
11 changes: 10 additions & 1 deletion src/utils/WarningMessage.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ export default class WarningMessage {
*/
constructor(msg, params = null) {
this.msg = msg
this.params = params
this.params = params ?? {}
}

isEquals(object) {
return (
object instanceof WarningMessage &&
object.msg === this.msg &&
Object.keys(this.params).length === Object.keys(object.params).length &&
Object.keys(this.params).every((key) => this.params[key] === object.params[key])
)
}
}
Loading