Skip to content

Commit 3f58364

Browse files
Merge pull request #228 from getsentry/handle-error-send-test-event
Handle :error when sending test event
2 parents 6287366 + 7597cfe commit 3f58364

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/mix/tasks/sentry.send_test_event.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ defmodule Mix.Tasks.Sentry.SendTestEvent do
5353
case result do
5454
{:ok, id} ->
5555
Mix.shell.info "Test event sent! Event ID: #{id}"
56+
:error ->
57+
Mix.shell.info "Error sending event!"
5658
:excluded ->
5759
Mix.shell.info "No test event was sent because the event was excluded by a filter"
5860
end

lib/sentry/client.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ defmodule Sentry.Client do
139139
error_header = :proplists.get_value("X-Sentry-Error", headers, "")
140140
log_api_error("#{body}\nReceived #{status} from Sentry server: #{error_header}")
141141
:error
142-
_ ->
143-
log_api_error(body)
142+
e ->
143+
log_api_error("#{inspect(e)}\n#{body}")
144144
:error
145145
end
146146
end

test/mix/sentry.send_test_event_test.exs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule Mix.Tasks.Sentry.SendTestEventTest do
22
use ExUnit.Case
33
import ExUnit.CaptureIO
4+
import ExUnit.CaptureLog
45
import Sentry.TestEnvironmentHelper
56

67
test "prints if environment_name is not in included_environments" do
@@ -46,4 +47,29 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
4647
Test event sent! Event ID: 340
4748
"""
4849
end
50+
51+
test "handles :error when Sentry server is failing" do
52+
bypass = Bypass.open
53+
Bypass.expect bypass, fn conn ->
54+
{:ok, _body, conn} = Plug.Conn.read_body(conn)
55+
Plug.Conn.resp(conn, 500, ~s<{"id": "340"}>)
56+
end
57+
modify_env(:sentry, [dsn: "http://public:secret@localhost:#{bypass.port}/1"])
58+
assert capture_log(fn ->
59+
assert capture_io(fn ->
60+
Mix.Tasks.Sentry.SendTestEvent.run([])
61+
end) == """
62+
Client configuration:
63+
server: http://localhost:#{bypass.port}/api/1/store/
64+
public_key: public
65+
secret_key: secret
66+
included_environments: [:test]
67+
current environment_name: :test
68+
hackney_opts: [recv_timeout: 50]
69+
70+
Sending test event...
71+
Error sending event!
72+
"""
73+
end) =~ "Failed to send Sentry event"
74+
end
4975
end

0 commit comments

Comments
 (0)