appcues / mojito

An easy-to-use Elixir HTTP client, built on the low-level Mint library.
https://hexdocs.pm/mojito/Mojito.html
MIT License
349 stars 34 forks source link

Handle when the url is nil #12

Closed intentionally-left-nil closed 5 years ago

intentionally-left-nil commented 5 years ago

Instead of returning an error struct when passing in a nil url, this PR causes a functionclause error to be thrown, leading to quicker debugging:

Mojito.request(:get, nil) ** (FunctionClauseError) no function clause matching in Mojito.request/5

The following arguments were given to Mojito.request/5:

    # 1
    :get

    # 2
    nil

    # 3
    []

    # 4
    ""

    # 5
    []

Attempted function clauses (showing 1 out of 1):

    def request(method, url, headers, payload, opts) when is_binary(url)

(mojito) lib/mojito.ex:91: Mojito.request/5
gamache commented 5 years ago

Thanks for the issue and PR! request/5 is designed to not raise exceptions, though, so rather than merging this PR, I'll add a patch to return a response of {:error, "URL cannot be nil"} or something like that.