错误行为
¥Error behavior
当策略检查失败时,Node.js 默认会抛出错误。通过在策略清单中定义 "onerror" 字段,可以将错误行为更改为几种可能性之一。以下值可用于更改行为:
¥When a policy check fails, Node.js by default will throw an error. It is possible to change the error behavior to one of a few possibilities by defining an "onerror" field in a policy manifest. The following values are available to change the behavior:
- 
"exit":将立即退出进程。不允许运行任何清理代码。¥
"exit": will exit the process immediately. No cleanup code will be allowed to run. - 
"log":将在发生故障的地方记录错误。¥
"log": will log the error at the site of the failure. - 
"throw":将在失败的地方抛出 JS 错误。这是默认值。¥
"throw": will throw a JS error at the site of the failure. This is the default. 
{
  "onerror": "log",
  "resources": {
    "./app/checked.js": {
      "integrity": "sha384-SggXRQHwCG8g+DktYYzxkXRIkTiEYWBHqev0xnpCxYlqMBufKZHAHQM3/boDaI/0"
    }
  }
}