TheFirstAvenger / elixir-ex_jira

Elixir wrapper for the JIRA REST API
MIT License
3 stars 8 forks source link

`Request.get_more/5` returning an unhandled response type upon second request #3

Closed wolves closed 5 years ago

wolves commented 5 years ago

ERROR:

17:51:30.119 [debug] ExJira.Request: Sending GET to https://jira.company_name.com/rest/api/latest/dashboard?startAt=20&&maxResults=300 using Elixir.HTTPotion
** (FunctionClauseError) no function clause matching in ExJira.Request.get_more/5

    The following arguments were given to ExJira.Request.get_more/5:

        # 1
        {:ok, %{"errorMessages" => ["The 'startAt' param (300) must be a multiple of the 'maxResults' param (20)"], "errors" => %{}}}

        # 2
         ...
        [truncated]

I believe it is related to this line:

https://github.com/TheFirstAvenger/elixir-ex_jira/blame/master/lib/ex_jira/utils/request.ex#L66

Is there a reason that the request is being constructed with a maxResult of 300 rather than just using the "next" => "https://jira.company_name.com/rest/api/latest/dashboard?maxResults=20&startAt=20" provided by the response from the previous request?

Seen here:

  ...

  "maxResults" => 20,
  "next" => "https://jira.company_name.com/rest/api/latest/dashboard?maxResults=20&startAt=20",
  "startAt" => 0,
  "total" => 27
}

The other issue that I noticed was the double ampersand in the request uri that is an effect of #{query_params} being placed in the middle of this line:

request( "GET", resource_path, "startAt=#{length(prev_items) + length(items)}&#{query_params}&maxResults=300", "" )

and then resolving to nil.

If it is alright with you I am working on a PR to resolve this issue, and is why I had the question regarding why maxResult is jumping from 20 to 300 after the first iteration.

I will try and get a PR up in the next day, work permitting.

wolves commented 5 years ago

PR Here: https://github.com/TheFirstAvenger/elixir-ex_jira/pull/4

Let me know what you think.

TheFirstAvenger commented 5 years ago

Thanks for the PR!