mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
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:
@ -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) {
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user