Skip to content

Commit

Permalink
fix(ui): show error in UI if signal filter name already exists (#5606)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Dec 14, 2024
1 parent 409cf02 commit 27c40d7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
42 changes: 12 additions & 30 deletions src/dispatch/signal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,9 @@ def create_engagement(
db_session=db_session, creator=current_user, signal_engagement_in=signal_engagement_in
)
except IntegrityError:
raise ValidationError(
[
ErrorWrapper(
ExistsError(msg="A signal engagement with this name already exists."),
loc="name",
)
],
model=SignalEngagementRead,
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[{"msg": "A signal engagement with this name already exists."}],
) from None


Expand Down Expand Up @@ -195,14 +190,9 @@ def update_engagement(
signal_engagement_in=signal_engagement_in,
)
except IntegrityError:
raise ValidationError(
[
ErrorWrapper(
ExistsError(msg="A signal engagement with this name already exists."),
loc="name",
)
],
model=SignalEngagementUpdate,
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[{"msg": "A signal engagement with this name already exists."}],
) from None

return signal_engagement
Expand All @@ -220,13 +210,9 @@ def create_filter(
db_session=db_session, creator=current_user, signal_filter_in=signal_filter_in
)
except IntegrityError:
raise ValidationError(
[
ErrorWrapper(
ExistsError(msg="A signal filter with this name already exists."), loc="name"
)
],
model=SignalFilterRead,
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[{"msg": "A signal filter with this name already exists."}],
) from None


Expand All @@ -253,13 +239,9 @@ def update_filter(
db_session=db_session, signal_filter=signal_filter, signal_filter_in=signal_filter_in
)
except IntegrityError:
raise ValidationError(
[
ErrorWrapper(
ExistsError(msg="A signal filter with this name already exists."), loc="name"
)
],
model=SignalFilterUpdate,
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[{"msg": "A signal filter with this name already exists."}],
) from None

return signal_filter
Expand Down
19 changes: 16 additions & 3 deletions src/dispatch/static/dispatch/src/signal/engagement/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ const actions = {
commit("RESET_SELECTED")
return resp.data
})
.catch((error) => {
console.log(error)
.catch((err) => {
let errorText = err.response.data.detail.map(({ msg }) => msg).join(" ")
commit(
"notification_backend/addBeNotification",
{ text: `Error trying to save: ${errorText}`, type: "exception" },
{ root: true }
)
commit("RESET_SELECTED")
commit("SET_SELECTED_LOADING", false)
})
} else {
Expand All @@ -55,7 +61,14 @@ const actions = {
)
commit("SET_SELECTED_LOADING", false)
})
.catch(() => {
.catch((err) => {
let errorText = err.response.data.detail.map(({ msg }) => msg).join(" ")
commit(
"notification_backend/addBeNotification",
{ text: `Error trying to save: ${errorText}`, type: "exception" },
{ root: true }
)
commit("RESET_SELECTED")
commit("SET_SELECTED_LOADING", false)
})
}
Expand Down
18 changes: 16 additions & 2 deletions src/dispatch/static/dispatch/src/signal/filter/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ const actions = {
commit("SET_DIALOG_CREATE_EDIT", false)
return resp.data
})
.catch(() => {
.catch((err) => {
let errorText = err.response.data.detail.map(({ msg }) => msg).join(" ")
commit(
"notification_backend/addBeNotification",
{ text: `Error trying to save: ${errorText}`, type: "exception" },
{ root: true }
)
commit("RESET_SELECTED")
commit("SET_SELECTED_LOADING", false)
})
} else {
Expand All @@ -78,7 +85,14 @@ const actions = {
)
commit("SET_SELECTED_LOADING", false)
})
.catch(() => {
.catch((err) => {
let errorText = err.response.data.detail.map(({ msg }) => msg).join(" ")
commit(
"notification_backend/addBeNotification",
{ text: `Error trying to save: ${errorText}`, type: "exception" },
{ root: true }
)
commit("RESET_SELECTED")
commit("SET_SELECTED_LOADING", false)
})
}
Expand Down

0 comments on commit 27c40d7

Please sign in to comment.