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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user