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
Github API returns "Problems parsing JSON" since v2.50.0 #1370
Comments
Which debug method did you use, That, or a standalone example that reproduces the problem, will be most helpful. |
With |
Here is the complete diff between v2.49.0(upper) and v2.51.0(lower). The Validation Failed error is expected. It seemes to me that the body is stringified twice in 51. I call JSON.stringify(data) and pass the string to request. 17c17
< date: 'Fri, 23 Jan 2015 21:29:13 GMT',
---
> date: 'Fri, 23 Jan 2015 21:27:23 GMT',
22c22
< 'x-ratelimit-remaining': '4954',
---
> 'x-ratelimit-remaining': '4960',
37c37
< 'x-github-request-id': 'B2BC6CCA:1D6A:58C506C:54C2BD29',
---
> 'x-github-request-id': 'B2BC6CCA:1D69:3D1E7A1:54C2BCBB',
40c40
< 'x-served-by': '2811da37fbdda4367181b328b22b2499' },
---
> 'x-served-by': '474556b853193c38f1b14328ce2d1b7d' },
53,54c53,55
< 'content-length': 53 },
< body: '{"tag_name":"0.1.1","name":"Release 0.1.1","body":""}' } }
---
> 'content-type': 'application/json',
> 'content-length': 67 },
> body: '"{\\"tag_name\\":\\"0.1.1\\",\\"name\\":\\"Release 0.1.1\\",\\"body\\":\\"\\"}"' } }
59c60
< date: 'Fri, 23 Jan 2015 21:29:14 GMT',
---
> date: 'Fri, 23 Jan 2015 21:27:24 GMT',
61,62c62,63
< 'content-length': '195',
< status: '422 Unprocessable Entity',
---
> 'content-length': '89',
> status: '400 Bad Request',
64c65
< 'x-ratelimit-remaining': '4953',
---
> 'x-ratelimit-remaining': '4959',
75c76
< 'x-github-request-id': 'B2BC6CCA:1675:B671514:54C2BD2A',
---
> 'x-github-request-id': 'B2BC6CCA:1D68:26F3BE3:54C2BCBB',
78c79
< statusCode: 422,
---
> statusCode: 400,
80,83c81,83
< { message: 'Validation Failed',
< errors: [Object],
< documentation_url: 'https://developer.github.com/v3/repos/releases/#create-a-release' } } }
< Fatal error: Validation Failed(422)
---
> { message: 'Problems parsing JSON',
> documentation_url: 'https://developer.github.com/v3' } } }
> Fatal error: Problems parsing JSON(400)
|
Ah, I see. Here's your fix: ## github.js
Github.prototype._request = function (method, url, body, callback) {
return request({
method: method,
url: url,
headers: this.headers,
- body: body ? JSON.stringify(body) : undefined,
+ body: body || undefined,
json: true,
}, callbackWrapper(callback));
}
(btw, GitHub supports |
Already removed my stringify. I was assuming something like that. Passing the object to the body works. Thanks a lot for the quick help and the Github tip. |
I'm making a
POST
request to https://api.github.com/repos/bartinger/grunt-github-release-asset/releases to create a release.I used v2.47.0 before and everything worked fine, but when I upgraded to v2.51.0 I got
400 Problems parsing JSON
even though the json was valid. I narrowed it down and found out that a change between v2.49.0 and v2.50.0 is causing this error.I also enabled the debug mode and made a diff of the complete output, however both outputs where identical (besides dates and stuff).
Is this a bug in the package?
The code to reproduce the error is createRelease(...)
The text was updated successfully, but these errors were encountered: