JSON-related methods return JsonNodes instead of strings.
This commit is contained in:
parent
f605ce6feb
commit
04bd6aa69f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.*.sw?
|
.*.sw?
|
||||||
nimcache/
|
nimcache/
|
||||||
|
test/runner
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "JDB Software's opinionated extensions and auth layer for Jester."
|
description = "JDB Software's opinionated extensions and auth layer for Jester."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -29,8 +29,8 @@ template halt*(
|
|||||||
break allRoutes
|
break allRoutes
|
||||||
|
|
||||||
template sendJsonResp*(
|
template sendJsonResp*(
|
||||||
code: HttpCode,
|
body: JsonNode,
|
||||||
body: string = "",
|
code: HttpCode = Http200,
|
||||||
knownOrigins: seq[string],
|
knownOrigins: seq[string],
|
||||||
headersToSend: RawHeaders) =
|
headersToSend: RawHeaders) =
|
||||||
## Immediately send a JSON response and stop processing the request.
|
## Immediately send a JSON response and stop processing the request.
|
||||||
@ -56,16 +56,16 @@ template sendJsonResp*(
|
|||||||
"Content-Type": CONTENT_TYPE_JSON,
|
"Content-Type": CONTENT_TYPE_JSON,
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
body
|
$body
|
||||||
)
|
)
|
||||||
|
|
||||||
proc makeDataBody*(data: JsonNode): string = $(%*{"details":"","data":data })
|
proc makeDataBody*(data: JsonNode): JsonNode = %*{"details":"","data":data}
|
||||||
proc makeStatusBody*(details: string): string = $(%*{"details":details})
|
proc makeStatusBody*(details: string): JsonNode = %*{"details":details}
|
||||||
|
|
||||||
template sendErrorResp*(err: ref ApiError, knownOrigins: seq[string]): void =
|
template sendErrorResp*(err: ref ApiError, knownOrigins: seq[string]): void =
|
||||||
log().debug err.respMsg & ( if err.msg.len > 0: ": " & err.msg else: "")
|
log().debug err.respMsg & ( if err.msg.len > 0: ": " & err.msg else: "")
|
||||||
if not err.parent.isNil: log().debug " original exception: " & err.parent.msg
|
if not err.parent.isNil: log().debug " original exception: " & err.parent.msg
|
||||||
sendJsonResp(err.respCode, makeStatusBody(err.respMsg), knownOrigins, @{:})
|
sendJsonResp(makeStatusBody(err.respMsg), err.respCode, knownOrigins, @{:})
|
||||||
|
|
||||||
## CORS support
|
## CORS support
|
||||||
template sendOptionsResp*(
|
template sendOptionsResp*(
|
||||||
|
BIN
test/runner
BIN
test/runner
Binary file not shown.
@ -1,3 +1,3 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import ./tauth, ./tjson_util
|
import ./tauth, ./tjsonutils
|
||||||
|
Loading…
x
Reference in New Issue
Block a user