From 318a1118ec3c4ba1e80cf13b2197e37f2941c2f0 Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Wed, 1 Oct 2025 15:11:46 -0400 Subject: [PATCH] Implement Sentry.ReqClient for HTTP requests This module implements the Sentry.HTTPClient behaviour using the Req HTTP client. --- lib/sentry/req_client.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/sentry/req_client.ex diff --git a/lib/sentry/req_client.ex b/lib/sentry/req_client.ex new file mode 100644 index 00000000..d25e37ec --- /dev/null +++ b/lib/sentry/req_client.ex @@ -0,0 +1,24 @@ +defmodule Sentry.ReqClient do + @behaviour Sentry.HTTPClient + + @moduledoc """ + HTTP client for Sentry based on Req. + + This client implements the `Sentry.HTTPClient` behaviour. + It's based on the [Req](https://github.com/wojtekmach/req) Elixir HTTP client, + which is an *optional dependency* of this library. If you wish to use another + HTTP client, you'll have to implement your own `Sentry.HTTPClient`. See the + documentation for `Sentry.HTTPClient` for more information. + """ + + @impl true + def post(url, headers, body) do + case Req.post(url, headers: headers, body: body) do + {:ok, %{status: status, headers: headers, body: body}} -> + {:ok, status, headers, body} + + {:error, error} -> + {:error, error} + end + end +end