Simplify new error handling
This commit is contained in:
@@ -40,7 +40,7 @@ proc getBanner(user: User): string =
|
||||
|
||||
proc parseUser*(json: string): Profile =
|
||||
handleErrors:
|
||||
case error
|
||||
case error.code
|
||||
of suspended: return Profile(suspended: true)
|
||||
of userNotFound: return
|
||||
else: echo "[error - parseUser]: ", error
|
||||
|
||||
@@ -18,5 +18,5 @@ proc getImageUrl*(url: string): string =
|
||||
|
||||
template handleErrors*(body) =
|
||||
if json.startsWith("{\"errors"):
|
||||
let error {.inject.} = json.fromJson(Errors).errors[0].code
|
||||
body
|
||||
for error {.inject.} in json.fromJson(Errors).errors:
|
||||
body
|
||||
|
||||
@@ -13,3 +13,8 @@ type
|
||||
|
||||
Errors* = object
|
||||
errors*: seq[ErrorObj]
|
||||
|
||||
proc contains*(codes: set[Error]; errors: Errors): bool =
|
||||
for e in errors.errors:
|
||||
if e.code in codes:
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user