mirror of
https://github.com/status-im/NimYAML.git
synced 2025-01-11 20:14:19 +00:00
Better error handling in server
This commit is contained in:
parent
7eca93f988
commit
b2707f99d7
@ -20,6 +20,7 @@ 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"
|
||||||
|
try:
|
||||||
case @"style"
|
case @"style"
|
||||||
of "minimal": style = psMinimal
|
of "minimal": style = psMinimal
|
||||||
of "canonical": style = psCanonical
|
of "canonical": style = psCanonical
|
||||||
@ -31,26 +32,14 @@ routes:
|
|||||||
output = ""
|
output = ""
|
||||||
parser = newYamlParser()
|
parser = newYamlParser()
|
||||||
events = parser.parse(newStringStream(@"input"))
|
events = parser.parse(newStringStream(@"input"))
|
||||||
try:
|
|
||||||
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:
|
|
||||||
let e = (ref YamlParserError)(getCurrentException())
|
|
||||||
resultNode["code"] = %1
|
|
||||||
resultNode["line"] = %e.line
|
|
||||||
resultNode["column"] = %e.column
|
|
||||||
resultNode["message"] = %e.msg
|
|
||||||
resultNode["detail"] = %e.lineContent
|
|
||||||
resp resultNode.pretty, "application/json"
|
|
||||||
if not tokens:
|
if not tokens:
|
||||||
echo "outputting YAML"
|
var output = newStringStream()
|
||||||
var
|
|
||||||
output = newStringStream()
|
|
||||||
try:
|
|
||||||
transform(newStringStream(@"input"), output, style)
|
transform(newStringStream(@"input"), output, style)
|
||||||
resultNode["code"] = %0
|
resultNode["code"] = %0
|
||||||
resultNode["output"] = %output.data
|
resultNode["output"] = %output.data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user