FIX: Broken error reporting in modals (and other places) (#23680)

1. actually call `popupAjaxError`, thanks :P
2. don't close a modal on error
3. use `extractError()` instead of manually joining error messages
4. …or passing just the error object to `this.flash`
This commit is contained in:
Jarek Radosz
2023-09-27 17:11:44 +02:00
committed by GitHub
parent 1ad60b791c
commit 6adc67a7a8
11 changed files with 70 additions and 58 deletions

View File

@ -9,6 +9,7 @@ import { inject as service } from "@ember/service";
import { isBlank, isPresent } from "@ember/utils";
import { htmlSafe } from "@ember/template";
import { tracked } from "@glimmer/tracking";
import { extractError } from "discourse/lib/ajax-error";
const DEFAULT_HINT = htmlSafe(
I18n.t("chat.create_channel.choose_category.default_hint", {
@ -108,17 +109,16 @@ export default class ChatModalCreateChannel extends Component {
}
}
#createChannel(data) {
return this.chatApi
.createChannel(data)
.then((channel) => {
this.args.closeModal();
this.chatChannelsManager.follow(channel);
this.router.transitionTo("chat.channel", ...channel.routeModels);
})
.catch((e) => {
this.flash = e.jqXHR.responseJSON.errors[0];
});
async #createChannel(data) {
try {
const channel = await this.chatApi.createChannel(data);
this.args.closeModal();
this.chatChannelsManager.follow(channel);
this.router.transitionTo("chat.channel", ...channel.routeModels);
} catch (e) {
this.flash = extractError(e);
}
}
#buildCategorySlug(category) {

View File

@ -2,6 +2,7 @@ import Component from "@glimmer/component";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { inject as service } from "@ember/service";
import { extractError } from "discourse/lib/ajax-error";
const DESCRIPTION_MAX_LENGTH = 280;
@ -27,18 +28,16 @@ export default class ChatModalEditChannelDescription extends Component {
}
@action
onSaveChatChannelDescription() {
return this.chatApi
.updateChannel(this.channel.id, { description: this.editedDescription })
.then((result) => {
this.channel.description = result.channel.description;
this.args.closeModal();
})
.catch((event) => {
if (event.jqXHR?.responseJSON?.errors) {
this.flash = event.jqXHR.responseJSON.errors.join("\n");
}
async onSaveChatChannelDescription() {
try {
const result = await this.chatApi.updateChannel(this.channel.id, {
description: this.editedDescription,
});
this.channel.description = result.channel.description;
this.args.closeModal();
} catch (error) {
this.flash = extractError(error);
}
}
@action