Packages
tesla
1.1.0
1.20.0
1.18.3
1.18.2
1.18.1
1.18.0
1.17.0
1.16.0
1.15.3
1.15.2
1.15.1
1.15.0
1.14.3
1.14.2
1.14.1
1.14.0
1.13.2
1.13.1
1.13.0
1.12.3
1.12.2
1.12.1
1.12.0
1.11.2
1.11.1
1.11.0
1.10.3
1.10.2
1.10.1
1.10.0
1.9.0
1.8.1
retired
1.8.0
1.7.0
1.6.1
1.6.0
1.5.1
1.5.0
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.1
1.2.0
1.1.0
1.0.0
1.0.0-beta.1
0.10.0
0.9.0
0.8.0
0.7.2
0.7.1
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.2.2
0.2.1
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
HTTP client library, with support for middleware and multiple adapters.
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/tesla/migration.ex
defmodule Tesla.Migration do
## ALIASES
@breaking_alias "https://github.com/teamon/tesla/wiki/0.x-to-1.0-Migration-Guide#dropped-aliases-support-159"
@breaking_headers_map "https://github.com/teamon/tesla/wiki/0.x-to-1.0-Migration-Guide#headers-are-now-a-list-160"
@breaking_client_fun "https://github.com/teamon/tesla/wiki/0.x-to-1.0-Migration-Guide#dropped-client-as-function-176"
def breaking_alias!(_kind, _name, nil), do: nil
def breaking_alias!(kind, name, caller) do
raise CompileError,
file: caller.file,
line: caller.line,
description: """
#{kind |> to_string |> String.capitalize()} aliases and local functions has been removed.
Use full #{kind} name or define a middleware module #{
name |> to_string() |> String.capitalize()
}
#{snippet(caller)}
See #{@breaking_alias}
"""
end
def breaking_alias_in_config!(module) do
check_config(
Application.get_env(:tesla, module, [])[:adapter],
"config :tesla, #{inspect(module)}, adapter: "
)
check_config(Application.get_env(:tesla, :adapter), "config :tesla, adapter: ")
end
defp check_config(nil, _label), do: nil
defp check_config({module, _opts}, label) do
check_config(module, label)
end
defp check_config(module, label) do
unless elixir_module?(module) do
raise CompileError,
description: """
Calling
#{label}#{inspect(module)}
with atom as argument has been deprecated
Use
#{label}Tesla.Adapter.Name
instead
See #{@breaking_alias}
"""
end
end
## HEADERS AS LIST
def breaking_headers_map!(
{:__aliases__, _, [:Tesla, :Middleware, :Headers]},
{:%{}, _, _},
caller
) do
raise CompileError,
file: caller.file,
line: caller.line,
description: """
Headers are now a list instead of a map.
#{snippet(caller)}
See #{@breaking_headers_map}
"""
end
def breaking_headers_map!(_middleware, _opts, _caller), do: nil
## CLIENT FUNCTION
def client_function! do
raise RuntimeError,
message: """
Using anonymous function as client has been removed.
Use `Tesla.build_client` instead
See #{@breaking_client_fun}
"""
end
## UTILS
defp elixir_module?(atom) do
atom |> Atom.to_string() |> String.starts_with?("Elixir.")
end
defp snippet(caller) do
caller.file
|> File.read!()
|> String.split("\n")
|> Enum.at(caller.line - 1)
rescue
_ in File.Error -> ""
end
end