Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114186
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/tesla/middleware/tuples.ex b/lib/tesla/middleware/tuples.ex
deleted file mode 100644
index 9e01f77..0000000
--- a/lib/tesla/middleware/tuples.ex
+++ /dev/null
@@ -1,62 +0,0 @@
-defmodule Tesla.Middleware.Tuples do
- @behaviour Tesla.Middleware
-
- @moduledoc """
- Return `:ok` / `:error` tuples for successful HTTP transations, i.e. when the request is completed
- (no network errors etc) - but it can still be an application-level error (i.e. 404 or 500).
-
- **NOTE**: This middleware must be included as the first in the stack (before other middleware)
-
- ### Example usage
-
- ```
- defmodule MyClient do
- use Tesla
-
- plug Tesla.Middleware.Tuples
- plug Tesla.Middleware.JSON
- end
- ```
-
- ### Options
- - `:rescue_errors` - list exceptions to be rescued, defaults to `:all` (See below)
-
- The default behaviour is to rescue Tesla.Error exceptions but let other pass through.
- It can be customized by passing a `rescue_error:` option:
-
- ### Rescue other exceptions
-
- ```
- plug Tesla.Middleware.Tuples, rescue_errors: [MyCustomError]
- ```
-
- ### Rescue all exceptions
-
- ```
- plug Tesla.Middleware.Tuples, rescue_errors: :all
- ```
-
- """
- def call(env, next, opts) do
- {:ok, Tesla.run(env, next)}
- rescue
- ex in Tesla.Error ->
- {:error, ex}
-
- ex ->
- case opts[:rescue_errors] do
- nil ->
- reraise ex, System.stacktrace()
-
- :all ->
- {:error, ex}
-
- list ->
- if ex.__struct__ in list do
- {:error, ex}
- else
- reraise ex, System.stacktrace()
- end
- end
- end
-end
diff --git a/test/tesla/middleware/tuples_test.exs b/test/tesla/middleware/tuples_test.exs
deleted file mode 100644
index e711abd..0000000
--- a/test/tesla/middleware/tuples_test.exs
+++ /dev/null
@@ -1,54 +0,0 @@
-defmodule Tesla.Middleware.TuplesTest do
- use ExUnit.Case, async: false
-
- defmodule(Custom1, do: defexception(message: "Custom 1"))
- defmodule(Custom2, do: defexception(message: "Custom 2"))
-
- defmodule Client do
- use Tesla
-
- plug Tesla.Middleware.Tuples, rescue_errors: [Custom1]
- plug Tesla.Middleware.JSON
-
- adapter fn env ->
- case env.url do
- "/ok" ->
- env
-
- "/econnrefused" ->
- raise %Tesla.Error{message: "adapter error: :econnrefused}", reason: :econnrefused}
-
- "/custom-1" ->
- raise %Custom1{}
-
- "/custom-2" ->
- raise %Custom2{}
- end
- end
- end
-
- defmodule DefaultClient do
- use Tesla
-
- plug Tesla.Middleware.Tuples
-
- adapter fn _ -> raise %Custom1{} end
- end
-
- test "return {:ok, env} for successful transaction" do
- assert {:ok, %Tesla.Env{}} = Client.get("/ok")
- end
-
- test "return {:error, reason} for unsuccessful transaction" do
- assert {:error, %Tesla.Error{}} = Client.get("/econnrefused")
- end
-
- test "rescue listed custom exception" do
- assert {:error, %Custom1{}} = Client.get("/custom-1")
- end
-
- test "do not rescue not-listed custom exception" do
- assert catch_error(Client.get("/custom-2"))
- assert catch_error(DefaultClient.get("/"))
- end
-end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 10:09 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40093
Default Alt Text
(3 KB)
Attached To
Mode
R28 tesla
Attached
Detach File
Event Timeline
Log In to Comment