Skip to content

Commit

Permalink
Add the request!/1 function
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeMilan committed Apr 7, 2023
1 parent b06c7b4 commit 301b43d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/httpoison/base.ex
Expand Up @@ -419,6 +419,22 @@ defmodule HTTPoison.Base do
})
end

@doc """
Issues an HTTP request an `HTTPoison.Request` struct.
exception in case of failure.
`request!/1` works exactly like `request/1` but it returns just the
response in case of a successful request, raising an exception in case the
request fails.
"""
@spec request!(Request.t()) :: {:ok, Response.t() | AsyncResponse.t() | MaybeRedirect.t()}
def request!(%Request{} = request) do
case request(request) do
{:ok, response} -> response
{:error, %Error{reason: reason}} -> raise Error, reason: reason
end
end

@doc """
Issues an HTTP request with the given method to the given url, raising an
exception in case of failure.
Expand Down

0 comments on commit 301b43d

Please sign in to comment.