Closed lukerollans closed 3 years ago
So I was assuming that res.body was already JSONified.. it wasn't
body = JSON.parse res.body
Cheers
Could you share the code where you encountered this? When possible, githubot ought to do the JSON parsing for you, so this sounds like something I might want to fix.
@iangreenleaf encountered when creating a PR via the API
# Handle errors
gh.handleErrors (res) ->
# JSONify the response from Github
body = JSON.parse res.body
# Process error
if res.statusCode is 404
msg.send "You haven't forked that repo, _sir_"
else
err = body.errors[body.errors.length - 1].message or "No error defined"
msg.send "You twollop. #{err}"
gh.post "repos/#{process.env.HUBOT_GITHUB_ORG}/#{repo}/pulls", payload, (pr) ->
Without body = JSON.parse res.body
, res.body is just a standard string
Cool, thanks. This is probably something that should be parsed automatically, since we know that it's coming back as JSON. I'm gonna reopen and see if I can get this fixed.
May be related to #22.
Hey there,
Having a weird amount of trouble accessing any properties assigned in
res.body
withinhandleErrors
.EG (this is working, just providing context. I'm trying to expand on it but am getting an undefined issue that makes no sense to me):
This is the output from
console.log res.body
So,
msg.send "You twollop. #{res.body.errors[0].message}"
should read "You twollop. A pull request already exists for lukerollans:master", but I just getundefined
on anything underres.body
.. evenconsole.log res.body.message
What am I missing?