FIX: better handling of error on create DM (#25908)

Prior to this fix we were correctly failing but just returning a generic error.
This commit is contained in:
Joffrey JAFFEUX 2024-02-27 10:21:36 +01:00 committed by GitHub
parent 8bfa2bcf3a
commit bb079f54cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 6 deletions

View File

@ -17,6 +17,9 @@ class Chat::Api::DirectMessagesController < Chat::ApiController
on_failed_policy(:satisfies_dms_max_users_limit) do |policy| on_failed_policy(:satisfies_dms_max_users_limit) do |policy|
render_json_dump({ error: policy.reason }, status: 400) render_json_dump({ error: policy.reason }, status: 400)
end end
on_failed_policy(:can_create_direct_message) do |policy|
render_json_dump({ error: I18n.t("chat.errors.invalid_direct_message") }, status: 400)
end
on_failed_policy(:actor_allows_dms) do on_failed_policy(:actor_allows_dms) do
render_json_error(I18n.t("chat.errors.actor_disallowed_dms")) render_json_error(I18n.t("chat.errors.actor_disallowed_dms"))
end end

View File

@ -2,6 +2,7 @@ import Component from "@glimmer/component";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import DButton from "discourse/components/d-button"; import DButton from "discourse/components/d-button";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default class ChatUserCardButton extends Component { export default class ChatUserCardButton extends Component {
@service chat; @service chat;
@ -13,13 +14,20 @@ export default class ChatUserCardButton extends Component {
} }
@action @action
startChatting() { async startChatting() {
return this.chat try {
.upsertDmChannel({ usernames: [this.args.user.username] }) const channel = await this.chat.upsertDmChannel({
.then((channel) => { usernames: [this.args.user.username],
this.router.transitionTo("chat.channel", ...channel.routeModels);
this.appEvents.trigger("card:close");
}); });
if (channel) {
this.router.transitionTo("chat.channel", ...channel.routeModels);
}
} catch (error) {
popupAjaxError(error);
} finally {
this.appEvents.trigger("card:close");
}
} }
<template> <template>

View File

@ -94,6 +94,7 @@ en:
original_message_not_found: "The ancestor of the message you are replying to cannot be found or has been deleted." original_message_not_found: "The ancestor of the message you are replying to cannot be found or has been deleted."
thread_invalid_for_channel: "Thread is not part of the provided channel." thread_invalid_for_channel: "Thread is not part of the provided channel."
thread_does_not_match_parent: "Thread does not match parent message." thread_does_not_match_parent: "Thread does not match parent message."
invalid_direct_message: "You are not allowed to create this direct message."
reviewables: reviewables:
message_already_handled: "Thanks, but we've already reviewed this message and determined it does not need to be flagged again." message_already_handled: "Thanks, but we've already reviewed this message and determined it does not need to be flagged again."
actions: actions: