if (e instanceof JavaScriptException) {
message.append(toJson(((JavaScriptException) e).getValue()));
} else if (e instanceof EcmaError) {
final EcmaError ecmaError = (EcmaError) e;
message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(),
ecmaError.lineNumber(), ecmaError.lineSource()));
} else {
message.append(e.getMessage());
}
return message.toString();
}