Skip to content

Commit 101756c

Browse files
authored
Add specs and test for :too_many_retries (#793)
1 parent b89a721 commit 101756c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/sentry/client.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ defmodule Sentry.Client do
304304
:ok
305305
end
306306

307+
@spec maybe_log_send_result(
308+
{:error, any()} | {:ok, binary()},
309+
Sentry.CheckIn.t() | Event.t() | list(Event.t())
310+
) ::
311+
:ok | nil
307312
def maybe_log_send_result(send_result, events) do
308313
if is_list(events) && Enum.any?(events, &(&1.source == :logger)) do
309314
:ok

test/sentry/transport_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,24 @@ defmodule Sentry.TransportTest do
184184
assert_received {:request, ^ref}
185185
assert_received {:request, ^ref}
186186
end
187+
188+
test "fails when it exhausts retries and Sentry replies with 429", %{bypass: bypass} do
189+
envelope = Envelope.from_event(Event.create_event(message: "Hello"))
190+
test_pid = self()
191+
ref = make_ref()
192+
193+
Bypass.expect(bypass, "POST", "/api/1/envelope/", fn conn ->
194+
send(test_pid, {:request, ref})
195+
196+
conn
197+
|> Plug.Conn.put_resp_header("retry-after", "1")
198+
|> Plug.Conn.resp(429, ~s<{}>)
199+
end)
200+
201+
assert {:error, :too_many_retries} =
202+
Transport.post_envelope(envelope, HackneyClient, _retries = [])
203+
204+
assert_received {:request, ^ref}
205+
end
187206
end
188207
end

0 commit comments

Comments
 (0)