Commit 152c03af authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch '321659-handle-discord-errors' into 'master'

Handle RestClient errors in Discord integration

See merge request gitlab-org/gitlab!56112
parents 7891b938 ddbc229d
...@@ -59,6 +59,9 @@ class DiscordService < ChatNotificationService ...@@ -59,6 +59,9 @@ class DiscordService < ChatNotificationService
embed.description = (message.pretext + "\n" + Array.wrap(message.attachments).join("\n")).gsub(ATTACHMENT_REGEX, " \\k<entry> - \\k<name>\n") embed.description = (message.pretext + "\n" + Array.wrap(message.attachments).join("\n")).gsub(ATTACHMENT_REGEX, " \\k<entry> - \\k<name>\n")
end end
end end
rescue RestClient::Exception => error
log_error(error.message)
false
end end
def custom_data(data) def custom_data(data)
......
---
title: Handle RestClient errors in Discord integration
merge_request: 56112
author:
type: fixed
...@@ -67,5 +67,16 @@ RSpec.describe DiscordService do ...@@ -67,5 +67,16 @@ RSpec.describe DiscordService do
expect { subject.execute(sample_data) }.to raise_error(ArgumentError, /is blocked/) expect { subject.execute(sample_data) }.to raise_error(ArgumentError, /is blocked/)
end end
end end
context 'when the Discord request fails' do
before do
WebMock.stub_request(:post, webhook_url).to_return(status: 400)
end
it 'logs an error and returns false' do
expect(subject).to receive(:log_error).with('400 Bad Request')
expect(subject.execute(sample_data)).to be(false)
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment