mirror of
https://github.com/status-im/NimYAML.git
synced 2025-01-12 04:24:16 +00:00
Better error handling in server
This commit is contained in:
parent
7eca93f988
commit
b2707f99d7
@ -20,42 +20,31 @@ routes:
|
|||||||
headers["Pragma"] = "no-cache"
|
headers["Pragma"] = "no-cache"
|
||||||
headers["Cache-Control"] = "no-cache"
|
headers["Cache-Control"] = "no-cache"
|
||||||
headers["Expires"] = "0"
|
headers["Expires"] = "0"
|
||||||
case @"style"
|
try:
|
||||||
of "minimal": style = psMinimal
|
case @"style"
|
||||||
of "canonical": style = psCanonical
|
of "minimal": style = psMinimal
|
||||||
of "default": style = psDefault
|
of "canonical": style = psCanonical
|
||||||
of "json": style = psJson
|
of "default": style = psDefault
|
||||||
of "block": style = psBlockOnly
|
of "json": style = psJson
|
||||||
of "tokens":
|
of "block": style = psBlockOnly
|
||||||
var
|
of "tokens":
|
||||||
output = ""
|
var
|
||||||
parser = newYamlParser()
|
output = ""
|
||||||
events = parser.parse(newStringStream(@"input"))
|
parser = newYamlParser()
|
||||||
try:
|
events = parser.parse(newStringStream(@"input"))
|
||||||
for event in events:
|
for event in events:
|
||||||
output.add($event & "\n")
|
output.add($event & "\n")
|
||||||
resultNode["code"] = %0
|
resultNode["code"] = %0
|
||||||
resultNode["output"] = %output
|
resultNode["output"] = %output
|
||||||
resp resultNode.pretty, "application/json"
|
resp resultNode.pretty, "application/json"
|
||||||
tokens = true
|
tokens = true
|
||||||
except YamlParserError:
|
if not tokens:
|
||||||
let e = (ref YamlParserError)(getCurrentException())
|
var output = newStringStream()
|
||||||
resultNode["code"] = %1
|
transform(newStringStream(@"input"), output, style)
|
||||||
resultNode["line"] = %e.line
|
resultNode["code"] = %0
|
||||||
resultNode["column"] = %e.column
|
resultNode["output"] = %output.data
|
||||||
resultNode["message"] = %e.msg
|
|
||||||
resultNode["detail"] = %e.lineContent
|
|
||||||
resp resultNode.pretty, "application/json"
|
resp resultNode.pretty, "application/json"
|
||||||
if not tokens:
|
except YamlParserError:
|
||||||
echo "outputting YAML"
|
|
||||||
var
|
|
||||||
output = newStringStream()
|
|
||||||
try:
|
|
||||||
transform(newStringStream(@"input"), output, style)
|
|
||||||
resultNode["code"] = %0
|
|
||||||
resultNode["output"] = %output.data
|
|
||||||
resp resultNode.pretty, "application/json"
|
|
||||||
except YamlParserError:
|
|
||||||
let e = (ref YamlParserError)(getCurrentException())
|
let e = (ref YamlParserError)(getCurrentException())
|
||||||
resultNode["code"] = %1
|
resultNode["code"] = %1
|
||||||
resultNode["line"] = %e.line
|
resultNode["line"] = %e.line
|
||||||
@ -63,13 +52,13 @@ routes:
|
|||||||
resultNode["message"] = %e.msg
|
resultNode["message"] = %e.msg
|
||||||
resultNode["detail"] = %e.lineContent
|
resultNode["detail"] = %e.lineContent
|
||||||
resp resultNode.pretty, "application/json"
|
resp resultNode.pretty, "application/json"
|
||||||
except YamlPresenterJsonError:
|
except YamlPresenterJsonError:
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
resultNode["code"] = %2
|
resultNode["code"] = %2
|
||||||
resultNode["message"] = %e.msg
|
resultNode["message"] = %e.msg
|
||||||
headers["Content-Type"] = "application/json"
|
headers["Content-Type"] = "application/json"
|
||||||
resp resultNode.pretty, "application/json"
|
resp resultNode.pretty, "application/json"
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
let msg = "Name: " & $e.name & "\nMessage: " & e.msg &
|
let msg = "Name: " & $e.name & "\nMessage: " & e.msg &
|
||||||
"\nTrace:\n" & e.getStackTrace
|
"\nTrace:\n" & e.getStackTrace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user