Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
chaodhib committed Dec 7, 2022
1 parent b93504d commit 25f7ee0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/tesla/middleware/message_pack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ defmodule Tesla.Middleware.MessagePack do
with true <- encodable?(env),
{:ok, body} <- encode_body(env.body, opts) do
{:ok,
env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", encode_content_type(opts)}])}
env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", encode_content_type(opts)}])}
else
false -> {:ok, env}
error -> error
Expand All @@ -71,7 +71,7 @@ defmodule Tesla.Middleware.MessagePack do
defp encode_body(body, opts), do: process(body, :encode, opts)

defp encode_content_type(opts),
do: Keyword.get(opts, :encode_content_type, @default_encode_content_type)
do: Keyword.get(opts, :encode_content_type, @default_encode_content_type)

defp encodable?(%{body: nil}), do: false
defp encodable?(%{body: body}) when is_binary(body), do: false
Expand Down Expand Up @@ -109,7 +109,7 @@ defmodule Tesla.Middleware.MessagePack do
end

defp content_types(opts),
do: @default_decode_content_types ++ Keyword.get(opts, :decode_content_types, [])
do: @default_decode_content_types ++ Keyword.get(opts, :decode_content_types, [])

defp process(data, op, opts) do
case do_process(data, op, opts) do
Expand Down
6 changes: 4 additions & 2 deletions test/tesla/middleware/message_pack_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ defmodule Tesla.Middleware.MessagePackTest do
end

test "return error when decoding invalid msgpack format" do
assert {:error, {Tesla.Middleware.MessagePack, :decode, _}} = Client.get("/invalid-msgpack-format")
assert {:error, {Tesla.Middleware.MessagePack, :decode, _}} =
Client.get("/invalid-msgpack-format")
end
end

Expand All @@ -93,7 +94,8 @@ defmodule Tesla.Middleware.MessagePackTest do
{status, headers, body} =
case env.url do
"/decode" ->
{200, [{"content-type", "application/x-custom-msgpack"}], Msgpax.pack!(%{"value" => 123})}
{200, [{"content-type", "application/x-custom-msgpack"}],
Msgpax.pack!(%{"value" => 123})}
end

{:ok, %{env | status: status, headers: headers, body: body}}
Expand Down

0 comments on commit 25f7ee0

Please sign in to comment.