Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive 422 response when searching Issues #569

Closed
drwlrsn opened this issue Nov 10, 2020 · 6 comments · Fixed by #596
Closed

Receive 422 response when searching Issues #569

drwlrsn opened this issue Nov 10, 2020 · 6 comments · Fixed by #596
Assignees

Comments

@drwlrsn
Copy link
Contributor

drwlrsn commented Nov 10, 2020

Hi! I am pretty new to Scala so bear with me. I can't really pinpoint what's going wrong, but hopefully I can explain it well enough.

Version

github4s: v0.26.0

What I trying to do

I am trying to use the Issue Search to find Pull Requests in a project, that are open and have a particular label. In the REPL, I've tried:

client.issues.searchIssues(
	"", 
	List(OwnerParamInRepository("47degrees/github4s"), IssueTypePullRequest, LabelParam("bug"), IssueStateOpen))
.unsafeRunSync()

This returns response with a 422 status code:

GHResponse(Left(UnprocessableEntityError(Validation Failed, List(UnprocessableEntity(Search,q,InvalidFormatting)))),422, ...)

This results in a query string of +repo:47degrees/github4s+type:pr+label:bug+state:open. Although it looks a bit odd works fine as an API request.

I noticed if everything except the OwnerParamInRepository the search succeeds just fine.

Running

client.issues.searchIssues("", List(OwnerParamInRepository("47degrees/github4s"))).unsafeRunSync()

Returns a response of

github4s.GHResponse[github4s.domain.SearchIssuesResult] = GHResponse(Right(SearchIssuesResult(0,false,List())),200, ...)

Thanks for the great work!

@BenFradet
Copy link
Contributor

mmh weird, is the leading + the issue?

@drwlrsn
Copy link
Contributor Author

drwlrsn commented Nov 12, 2020

The leading + seems to be just fine. The following request works fine:

https://api.github.com/search/issues?q=+repo:47degrees/github4s+type:pr+label:enhancement+state:open

@drwlrsn
Copy link
Contributor Author

drwlrsn commented Nov 13, 2020

Ah okay I think I have some more info. IssuesInterpreter assembles a query here:

params = Map("q" -> s"${encode(query, "utf-8")}+${searchParams.map(_.value).mkString("+")}")

At this point the value of the q has a string value of: +repo:47degrees/github4s+type:pr+state:open+label:enhancement

I setup mitmproxy to check what the actual request looks like, and the request it intercepts looks like this:

GET https://140.82.113.6/search/issues?q=%2Brepo%3A47degrees/github4s%2Btype%3Apr%2Bstate%3Aopen%2Blabel%3Aenhancement

It seems like percent encoding the + and : chars is breaking the request

@BenFradet
Copy link
Contributor

good catch! 👍

@sloshy
Copy link
Contributor

sloshy commented Jan 12, 2021

I believe I've found the source of the issue. Whether or not it's a bug proper in http4s remains to be seen, but it appears that http4s uses different encoder settings for query parameters VS the main URL. I've submitted this to them as the above issue (the second one, the first was a similar issue I thought was related but was a bit different), so hopefully we will hear back soon!

@sloshy
Copy link
Contributor

sloshy commented Jan 13, 2021

Fix is posted above ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants