Skip to content

Commit

Permalink
Make it easier to debug json parsing error, refs #67
Browse files Browse the repository at this point in the history
  • Loading branch information
Huy Doan committed Dec 3, 2021
1 parent 22bbb3d commit e32207a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/telebot/private/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,14 @@ proc makeRequest*(b: Telebot, `method`: string, data: MultipartData = nil): Futu
defer: client.close()
let r = await client.post(endpoint, multipart=data)
if r.code == Http200 or r.code == Http400:
var obj = parse(await r.body)
if obj["ok"].toBool:
let body = await r.body
var obj: JsonNode
try:
obj = parse(body)
except:
raise newException(ValueError, "Parse JSON error: " & getCurrentExceptionMsg() & "\n" & body)

if obj.hasKey("ok") and obj["ok"].toBool:
result = obj["result"]
d("Result: ", $result)
else:
Expand Down

0 comments on commit e32207a

Please sign in to comment.