
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
contextual-error
Advanced tools
contextual-error
Emit errors described by a code and context.
yarn add contextual-error
# Or if you are using NPM:
# npm install --save contextual-error
import { ContextualError } from 'contextual-error';
type AppErrorContext = (
{
code: 'ServerError';
metadata: Record<string, never>;
}
| {
code: 'ValidationError';
metadata: {
name: string;
reason: string;
value?: unknown;
};
}
);
class AppError extends ContextualError<AppErrorContext> {}
try {
const request = {
age: 'abc',
};
if ('number' !== typeof request.age) {
throw new AppError({
code: 'ValidationError',
metadata: {
name: 'age',
reason: 'Value must be a number',
value: request.age,
},
});
}
} catch (err) {
console.log(err);
// AppError: ValidationError
// ...stack...
// context: {
// code: 'ValidationError',
// metadata: {
// name: 'age',
// reason: 'Value must be a number',
// value: 'abc',
// },
// },
// timestamp: '2000-01-01T00:00:00Z'
if (err instanceof AppError) {
switch (err.context.code) {
case 'ValidationError':
const { name, reason, value } = err.context.metadata;
alert(`Invalid value provided for "${name}". ${reason} but you provided "${String(value ?? '')}".`);
// Invalid value provided for "age". Value must be a number but you provided "abc".
break;
case 'ServerError':
alert('Please try again later.');
break;
}
}
}
FAQs
Emit errors described by a code and context.
The npm package contextual-error receives a total of 0 weekly downloads. As such, contextual-error popularity was classified as not popular.
We found that contextual-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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.