ansible / ansible-ui

The UIs for Ansible Projects such as AWX, EDA, and HUB.
https://ansible.github.io/ansible-ui/
Apache License 2.0
75 stars 65 forks source link

Update alert toaster to handle 'detail' errors #3050

Closed mabashian closed 2 months ago

mabashian commented 3 months ago

This came up while testing attempting to sync EDA projects when Redis is down. The API responds with a 409 error and a body that looks like:

{
  "detail": "Redis is required but unavailable."
}

This change allows us to show the contents of the error message to the user like this:

project_sync

Rather than the current UX:

project_sync_old

This got a little bit messier than I thought it would but I looked for instances where we're using errorToAlertProps and the majority of them are here in EDA. There are a couple in Hub that I don't think will be impacted as only the error object is a required parameter.

mabashian commented 3 months ago

@lgalis I abandoned the errorToAlertProps approach and rolled a small utility function to parse the error and display the string. That utility function could probably be much more robust but I think it'll get the job done here in the short term.

sonarcloud[bot] commented 2 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
12.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud