Skip to content

Commit 112ceb5

Browse files
GuillaumeMilanedgurgel
authored andcommitted
Add the request!/1 function
1 parent 711093f commit 112ceb5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/httpoison/base.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,22 @@ defmodule HTTPoison.Base do
419419
})
420420
end
421421

422+
@doc """
423+
Issues an HTTP request an `HTTPoison.Request` struct.
424+
exception in case of failure.
425+
426+
`request!/1` works exactly like `request/1` but it returns just the
427+
response in case of a successful request, raising an exception in case the
428+
request fails.
429+
"""
430+
@spec request!(Request.t()) :: {:ok, Response.t() | AsyncResponse.t() | MaybeRedirect.t()}
431+
def request!(%Request{} = request) do
432+
case request(request) do
433+
{:ok, response} -> response
434+
{:error, %Error{reason: reason}} -> raise Error, reason: reason
435+
end
436+
end
437+
422438
@doc """
423439
Issues an HTTP request with the given method to the given url, raising an
424440
exception in case of failure.

0 commit comments

Comments
 (0)