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 authored and edgurgel committed May 3, 2023
1 parent 711093f commit 112ceb5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/httpoison/base.ex
Original file line number Diff line number Diff line change
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 112ceb5

Please sign in to comment.