
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
graceful-error
Advanced tools
GracefulError 在 Node 原生错误对象 Error 的基础之上,新增了 8 个属性,如下所示。
注意:
ErrorLevelEnum 错误级别枚举对象,原始定义如下
const ErrorLevelEnum = {
INFO: 'info',
NOTICE: 'notice',
ALERT: 'alert',
WARN: 'warn',
ERROR: 'error',
CRITICAL: 'critical',
};
示例代码:
ErrorLevelEnum.INFO; // 'info'
ErrorLevelEnum.ERROR; // 'error'
参数说明:
options 错误配置对象
context 可选,错误上下文对象,适用于存储一些错误上下文信息
示例代码:
const { createError, ErrorLevelEnum } = require('graceful-error');
const err = createError(
{
message: 'Invalid HTTP header value.',
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
msg: '请求参数不合理',
level: ErrorLevelEnum.ERROR,
errorType: 'demo_type',
appId: 'demo',
logIndex: 'demo_log_index',
feature: 'demo_feature',
},
{
foo: 'bar',
}
);
将一个错误对象包装成 GracefulError 类型的错误。
参数说明:
const { wrapError } = require('graceful-error');
const oldError = new Error('hello world');
const newError = wrapError(oldError);
将 err 错误对象转换成一个 JSON 对象
const errJSON = err.toJSON();
FAQs
### 一、基础介绍
The npm package graceful-error receives a total of 0 weekly downloads. As such, graceful-error popularity was classified as not popular.
We found that graceful-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.