return usable error message when chat creation fails (#7629)
This commit is contained in:
parent
9ca423fed8
commit
2e67cc252e
2 changed files with 10 additions and 0 deletions
|
|
@ -80,6 +80,7 @@ class ChatChannelsController < ApplicationController
|
|||
chat_recipient = User.find(params[:user_id])
|
||||
valid_listing = ClassifiedListing.where(user_id: params[:user_id], contact_via_connect: true).limit(1)
|
||||
authorize ChatChannel
|
||||
|
||||
if chat_recipient.inbox_type == "open" || valid_listing.length == 1
|
||||
chat = ChatChannel.create_with_users(users: [current_user, chat_recipient], channel_type: "direct")
|
||||
message_markdown = params[:message]
|
||||
|
|
@ -93,6 +94,8 @@ class ChatChannelsController < ApplicationController
|
|||
else
|
||||
render json: { status: "error", message: "not allowed!" }, status: :bad_request
|
||||
end
|
||||
rescue StandardError => e
|
||||
render json: { status: "error", message: e.message }, status: :bad_request
|
||||
end
|
||||
|
||||
def block_chat
|
||||
|
|
|
|||
|
|
@ -237,6 +237,13 @@ RSpec.describe "ChatChannels", type: :request do
|
|||
params: { user_id: user_open_inbox.id }
|
||||
expect(user_open_inbox.chat_channel_memberships.size).to eq(1)
|
||||
end
|
||||
|
||||
it "returns error message if create_with_users fails" do
|
||||
allow(ChatChannel).to receive(:create_with_users).and_raise(StandardError.new("Blocked"))
|
||||
post "/chat_channels/create_chat",
|
||||
params: { user_id: user_open_inbox.id }
|
||||
expect(response.parsed_body["message"]).to eq("Blocked")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /chat_channels/block_chat" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue