Show command errors

I went with placing htis logic at the command level since it plays well with the composite structure, where you don't know whether you are handling one command or many commands, and you want to aggregate all the errors. I didn't leverage the existing support with rails' model errors because that customizing those message is cumbersome (either i18n or using custom validation logic for everything).
This commit is contained in:
Jorge Manrubia
2025-06-30 23:01:14 +02:00
parent eb3fc208a9
commit 179ae45bf3
4 changed files with 38 additions and 3 deletions
@@ -64,6 +64,7 @@ export default class extends Controller {
}
hideError() {
this.#hideOutput()
this.element.classList.remove(this.errorClass)
}
@@ -113,13 +114,15 @@ export default class extends Controller {
const status = response.status
if (status === HttpStatus.UNPROCESSABLE) {
this.#showError()
this.#showError(response)
} else if (status === HttpStatus.CONFLICT) {
await this.#handleConflictResponse(response)
}
}
#showError() {
async #showError(response) {
const message = await response.json()
this.#showOutput(message.error)
this.element.classList.add(this.errorClass)
}