Why Does Attempting to Serialize A JsError Throw A JsonException #1381
-
I'm attempting to create essentially a repl where...
Here is what I'm doing so far: var runResult = _formulaService.RunFormula(request.Formula);
response.Result = runResult.Value;
if (runResult.IsValid is false)
{
response.Error = runResult.Exception.Message;
return BadRequest(response);
}
return Ok(response); And here is what the _formulaService.RunFormula` method is doing var result = new FormulaRunResult();
try
{
result.Value = _engine.Evaluate(formula, _parserOptions).ToObject();
}
catch(Exception e) when (e is JavaScriptException || e is ParserException)
{
result.Exception = e;
}
return result; However what I've found is that I run into a serialization issue if a user enters a script where they attempt to catch and return a javascript error. Something like this: try {
throw new Error('oh no');
}
catch (err) {
return err;
} I'd expect that this would just return an empty object, but instead an exception is thrown. I've added that below. Would anyone be able to enlighten me about what I might be doing wrong to have created this issue?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm afraid an |
Beta Was this translation helpful? Give feedback.
I'm afraid an
Error
instance (and probably many more) haven't been designed to cope with STJ. Jint has it's ownJsonSerializer
which knows which properties to include (enumerable).