diff --git a/.gitignore b/.gitignore index 27b4ec6..085cf37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .*.sw? nimcache/ +test/runner diff --git a/buffoonery.nimble b/buffoonery.nimble index cf7f2d6..cf413b6 100644 --- a/buffoonery.nimble +++ b/buffoonery.nimble @@ -1,6 +1,6 @@ # Package -version = "0.1.1" +version = "0.2.0" author = "Jonathan Bernard" description = "JDB Software's opinionated extensions and auth layer for Jester." license = "MIT" diff --git a/src/buffoonery/apiutils.nim b/src/buffoonery/apiutils.nim index 5538c63..454c489 100644 --- a/src/buffoonery/apiutils.nim +++ b/src/buffoonery/apiutils.nim @@ -29,8 +29,8 @@ template halt*( break allRoutes template sendJsonResp*( - code: HttpCode, - body: string = "", + body: JsonNode, + code: HttpCode = Http200, knownOrigins: seq[string], headersToSend: RawHeaders) = ## Immediately send a JSON response and stop processing the request. @@ -56,16 +56,16 @@ template sendJsonResp*( "Content-Type": CONTENT_TYPE_JSON, "Cache-Control": "no-cache" }, - body + $body ) -proc makeDataBody*(data: JsonNode): string = $(%*{"details":"","data":data }) -proc makeStatusBody*(details: string): string = $(%*{"details":details}) +proc makeDataBody*(data: JsonNode): JsonNode = %*{"details":"","data":data} +proc makeStatusBody*(details: string): JsonNode = %*{"details":details} template sendErrorResp*(err: ref ApiError, knownOrigins: seq[string]): void = log().debug err.respMsg & ( if err.msg.len > 0: ": " & err.msg else: "") 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 template sendOptionsResp*( diff --git a/test/runner b/test/runner deleted file mode 100755 index b2dab07..0000000 Binary files a/test/runner and /dev/null differ diff --git a/test/runner.nim b/test/runner.nim index 730b9ad..5b62786 100644 --- a/test/runner.nim +++ b/test/runner.nim @@ -1,3 +1,3 @@ import unittest -import ./tauth, ./tjson_util +import ./tauth, ./tjsonutils