错误的行为


当策略检查失败时,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": will exit the process immediately. No cleanup code will be allowed to run.
    • "log": will log the error at the site of the failure.
    • "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"
        }
      }
    }