daneden / Twift

🐦 An async Swift library for the Twitter v2 API 🚧 WIP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User lookup by usernames Error response issue

emin-grbo opened this issue · comments

commented

I am not 100% sure if my setup is wrong, but if one searches for multiple users, ie, the request has an array of parameters....if one of them produces an error, the whole response is nil 🤷‍♂️

Here is the example of such a response on twitter developer portal:
image

@daneden
You can see in the screenshot what is the setup. Basically, find a character that produces an error ("e" is one of them), and send several other strings along with it in a single response.

commented

image

So it seems it is not fully migrated, but possibly not planned at all? 🤷‍♂️

@roblack thanks for reporting this issue! First it's worth pointing out that “user lookup” is different from “user search”.

  • User lookup assumes that you already know the complete username of the user you’re trying to fetch info for (i.e. a lookup for ja would only return the user @ja)
  • User search is a function to find users by username with an incomplete string (i.e. a search for ja might return @jack)

User search is not (yet) in the V2 API, but lookup is. Nevertheless, the error you reported is valid and needs fixing; when a subset of user names passed to the lookup endpoint returns an error, Twift should return an array of error objects instead of returning an error for the whole request.

I found the cause of this bug!

In the decodeOrThrow method that is responsible for decoding all requests to the Twitter API, I had written the method in a way that always throws errors when they’re encountered, even if a successful payload is returned along with errors.

In 1f47b93, I changed it so that Twift only throws errors when found if a successful response can’t be decoded.