0

I have the following function in one module:

  def create_chart(data) do
    url = "https://quickchart.io/chart/create"

    case HTTPoison.post!(
           url,
           data,
           [
             {"Content-Type", "application/json"}
           ],
           hackney: [:insecure]
         ) do
      {:ok, response} -> return_url(response)
      {:error, reason} -> IO.inspect(reason)
    end
  end

This gets called at the end after I collect a bunch of data from JIRA. The data from JIRA comes from this method in a different module. This method gets called many times before generating the graph above (see previous code).

  def get(url) do
    {:ok, response} = HTTPoison.get(url, [auth()], hackney: [:insecure, basic_auth: auth()])
    response.body
  end

Once I collect the data and called QuickChart, I get very weird behaviour while calling the QuickChart API:

** (MatchError) no match of right hand side value: {:error, {:unexpected_token, "<!DOCTYPE html><html lang=\"en\"><head><title>Oops, you&#39;ve found a dead link. - JIRA</title>....</html>"}}
    (km 0.1.0) lib/charts_api.ex:41: KM.Charts.Api.return_url/1

I've omitted the response for brevity, but what's happening is that instead of calling https://quickchart.io/chart/create, it's calling http://myjirasubdomain.atlassian.net/chart/create

When I remove all calls to JIRA and hardcode the data for QuickChart, it works fine. So there's something about the "previous" JIRA calls that's affecting the endpoint base when calling QuickChart.

I'm not sure why this is happening. Any help is appreciated.

Nightwolf
  • 4,495
  • 2
  • 21
  • 29
  • Why are you passing `auth()` as both a header and a hackney option? I think the hackney option is `{"username", "password"}`, which probably wouldn't make a great header. – Brett Beatty Feb 11 '20 at 21:55
  • I don't know enough about the internals of hackney to know if there's a cause in common (other than symptoms it doesn't appear there should be), but it looks like someone else has had an issue with it holding onto SSL options for different calls to the same host: https://github.com/benoitc/hackney/issues/570 – Brett Beatty Feb 11 '20 at 22:03
  • I thought the problem was that because I was using `use HTTPoison.Base` instead of `get` and `post` of the modules that I created. Turns out that wasn't the case. I ended up switching to Tesla instead of Poison and it's working perfectly. – Nightwolf Feb 13 '20 at 03:30

0 Answers0