edgurgel / tentacat

Simple Elixir wrapper for the GitHub API

Home Page:https://hexdocs.pm/tentacat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

0.9.0 API is inconsistent. Some requests still return body instead of tuple {code, body, response}

smetana opened this issue · comments

Tentacat.Organizations.list_mine(client) # returns tuple
Tentacat.Repositories.list_mine(client) # returns list

Yes that's a bug! We should always return the tuple! Thanks for creating the issue

I took a quick look at this, but it does not seem to be straightforward to fix for me (and record a test), since it is definitely related to pagination.

As far as I can work it out from the test, this seems to be intended behaviour for functions that take pagination options.

  • pagination: :none will return the expected {status, body, response} tuple for the first page.
  • pagination: nil and pagination: :auto will return a list of all resulting elements, going through all pages automagically.
  • pagination: :stream will return an Enumerable function constructed from Stream.resource.
  • pagination: :manual will return a {{status, body, response}, next_link, auth} tuple.

This is definitely surprising behaviour at least for @smetana and me. But changing it could break things for a lot of people.

First of all, should I document this? Secondly, what to do about it?
@edgurgel Any ideas?

hi, i'm having the same problem here, i'm using the Repository.Tags and it has the same problem you are describing, also i ran the dialyxir task mix dialyzer and got a lot of errors e.g in Repository.Tags.list Function list/2 has no local return because it returns the error tuples correctly ({integer, any, HTTPoison.Response.t()}) but not the success tuple {:ok, :jsx.json_term(), HTTPoison.Response.t()} because it only returns the body already decoded by JSX

I have a fix for the original issue in this thread (returning lists instead of tuples). will open a pull request soon!

I'd suggest we open a new issue for the error tuple always getting returned so we can track that separately. (I think I can resolve that as well with a little more time)