Error stuff
This commit is contained in:
parent
0859d8c2d9
commit
39863703b3
|
@ -1,6 +1,10 @@
|
|||
import json, strutils, options, tables, times, math
|
||||
import types, parserutils
|
||||
|
||||
proc parseError(js: JsonNode): Error =
|
||||
if js == nil or js.kind != JArray or js.len < 1: return null
|
||||
return Error(js[0]{"code"}.getInt)
|
||||
|
||||
proc parseProfile(js: JsonNode; id=""): Profile =
|
||||
if js == nil: return
|
||||
result = Profile(
|
||||
|
@ -24,12 +28,12 @@ proc parseProfile(js: JsonNode; id=""): Profile =
|
|||
result.expandProfileEntities(js)
|
||||
|
||||
proc parseGraphProfile*(js: JsonNode; username: string): Profile =
|
||||
with errors, js{"errors"}:
|
||||
for error in errors:
|
||||
case Error(error{"code"}.getInt)
|
||||
of notFound: return Profile(username: username)
|
||||
of suspended: return Profile(username: username, suspended: true)
|
||||
else: discard
|
||||
if js == nil: return
|
||||
with error, js{"errors"}:
|
||||
result = Profile(username: username)
|
||||
if parseError(error) == suspended:
|
||||
result.suspended = true
|
||||
return
|
||||
|
||||
let user = js{"data", "user", "legacy"}
|
||||
let id = js{"data", "user", "rest_id"}.getStr
|
||||
|
|
|
@ -13,10 +13,11 @@ type
|
|||
# agent*: string
|
||||
|
||||
Error* = enum
|
||||
null = 0
|
||||
protectedUser = 22
|
||||
couldntAuth = 32
|
||||
doesntExist = 34
|
||||
notFound = 50
|
||||
userNotFound = 50
|
||||
suspended = 63
|
||||
invalidToken = 89
|
||||
listIdOrSlug = 112
|
||||
|
|
Loading…
Reference in New Issue