Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

new-error

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

new-error - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

6

build/error-types/BaseError.d.ts

@@ -19,3 +19,3 @@ import ExtendableError from 'es6-error';

*/
protected withErrorType(type: string): this;
withErrorType(type: string): this;
/**

@@ -25,3 +25,3 @@ * Set high level error code

*/
protected withErrorCode(code: string | number): this;
withErrorCode(code: string | number): this;
/**

@@ -31,3 +31,3 @@ * Set low level error code

*/
protected withErrorSubCode(subCode: string | number): this;
withErrorSubCode(subCode: string | number): this;
/**

@@ -34,0 +34,0 @@ * Returns the status code.

import { BaseError } from '../index';
import { HighLevelErrorDef, LowLevelErrorInternal } from '../interfaces';
import { HighLevelError, LowLevelErrorInternal } from '../interfaces';
/**

@@ -7,3 +7,3 @@ * Improved error class generated by the ErrorRegistry.

export declare class BaseRegistryError extends BaseError {
constructor(highLevelErrorDef: HighLevelErrorDef, lowLevelErrorDef: LowLevelErrorInternal);
constructor(highLevelErrorDef: HighLevelError, lowLevelErrorDef: LowLevelErrorInternal);
}

@@ -1,2 +0,2 @@

import { HighLevelErrorDef, LowLevelErrorInternal, LowLevelErrorDef } from './interfaces';
import { HighLevelErrorInternal, LowLevelErrorInternal } from './interfaces';
import { BaseRegistryError } from './error-types/BaseRegistryError';

@@ -7,7 +7,7 @@ /**

*/
export declare class ErrorRegistry<ErrCode extends LowLevelErrorDef, HLError extends Record<keyof HLError, HighLevelErrorDef>, LLErrorName extends Record<keyof LLErrorName, LowLevelErrorDef>, LLError extends Record<keyof LLErrorName, LowLevelErrorInternal>> {
export declare class ErrorRegistry<ErrCode extends LowLevelErrorInternal, HLError extends Record<keyof HLError, HighLevelErrorInternal>, LLErrorName extends Record<keyof LLErrorName, LowLevelErrorInternal>, LLError extends Record<keyof LLErrorName, LowLevelErrorInternal>> {
/**
* High level error definitions
*/
protected highLevelErrors: Record<keyof HLError, HighLevelErrorDef>;
protected highLevelErrors: Record<keyof HLError, HighLevelErrorInternal>;
/**

@@ -26,3 +26,3 @@ * Cached high level error classes

*/
protected getHighLevelError(highLvErrName: keyof HLError): HighLevelErrorDef;
protected getHighLevelError(highLvErrName: keyof HLError): HighLevelErrorInternal;
/**

@@ -29,0 +29,0 @@ * Gets the definition of a Low Level Error

import { BaseError } from './error-types/BaseError';
import { BaseRegistryError } from './error-types/BaseRegistryError';
import { ErrorRegistry } from './ErrorRegistry';
import { IBaseError, SerializedError, SerializedErrorSafe } from './interfaces';
export { BaseError, ErrorRegistry, IBaseError, SerializedError, SerializedErrorSafe };
import { IBaseError, SerializedError, SerializedErrorSafe, HighLevelError, LowLevelError } from './interfaces';
export { BaseError, BaseRegistryError, ErrorRegistry, IBaseError, HighLevelError, LowLevelError, SerializedError, SerializedErrorSafe };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorRegistry = exports.BaseError = void 0;
exports.ErrorRegistry = exports.BaseRegistryError = exports.BaseError = void 0;
const BaseError_1 = require("./error-types/BaseError");
Object.defineProperty(exports, "BaseError", { enumerable: true, get: function () { return BaseError_1.BaseError; } });
const BaseRegistryError_1 = require("./error-types/BaseRegistryError");
Object.defineProperty(exports, "BaseRegistryError", { enumerable: true, get: function () { return BaseRegistryError_1.BaseRegistryError; } });
const ErrorRegistry_1 = require("./ErrorRegistry");
Object.defineProperty(exports, "ErrorRegistry", { enumerable: true, get: function () { return ErrorRegistry_1.ErrorRegistry; } });
//# sourceMappingURL=index.js.map
/**
* A High Level Error definition defined by the user
*/
export interface HighLevelErrorDef {
export interface HighLevelError {
/**
* The class name of the generated error
*/
className: string;
/**
* A user-friendly code to show to a client that represents the high

@@ -21,2 +17,11 @@ * level error.

/**
* A High Level Error definition defined by the user for a registry
*/
export interface HighLevelErrorInternal extends HighLevelError {
/**
* The class name of the generated error
*/
className: string;
}
/**
* A Low Level Error definition defined by the user

@@ -50,2 +55,11 @@ */

}
/**
* A Low Level Error definition defined by the user when a registry is not involved
*/
export interface LowLevelError extends LowLevelErrorDef {
/**
* Name of the Low Level Error
*/
type: string;
}
export interface IBaseError {

@@ -52,0 +66,0 @@ /**

@@ -0,1 +1,10 @@

## 1.0.6 - Fri May 15 2020 23:34:12
**Contributor:** Theo Gravity
- [minor] Concrete class-based support (#1)
- Added examples on how to work with the library without the registry
- Updated and exported some interfaces to assist with class-based creation
## 1.0.5 - Fri May 15 2020 20:57:38

@@ -2,0 +11,0 @@

{
"name": "new-error",
"version": "1.0.5",
"version": "1.0.6",
"description": "A production-grade error creation and serialization library designed for Typescript",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -26,2 +26,5 @@ # new-error

- [Example Usage](#example-usage)
- [With the error registry](#with-the-error-registry)
- [Class-based with low level errors without a registry](#class-based-with-low-level-errors-without-a-registry)
- [Bare-bones class-based error](#bare-bones-class-based-error)
- [Error Registry](#error-registry)

@@ -54,2 +57,4 @@ - [Creating errors](#creating-errors)

## With the error registry
- Define a set of high level errors

@@ -148,2 +153,51 @@ * Common high level error types could be 4xx/5xx HTTP codes

## Class-based with low level errors without a registry
You can create concrete error classes by extending the `BaseRegistryError` class, which
extends the `BaseError` class.
The registry example can be also written as:
```typescript
import { BaseRegistryError, LowLevelError } from 'new-error'
class InternalServerError extends BaseRegistryError {
constructor (errDef: LowLevelError) {
super({
code: 'ERR_INT_500',
statusCode: 500
}, errDef)
}
}
const err = new InternalServerError({
type: 'DATABASE_FAILURE',
message: 'There was a database failure, SQL err code %s',
subCode: 'DB_0001',
statusCode: 500
})
console.log(err.formatMessage('SQL_1234').toJSON())
```
## Bare-bones class-based error
If you want a native-style `Error`, you can use `BaseError`.
The registry example can be written as:
```typescript
import { BaseError } from 'new-error'
class InternalServerError extends BaseError {}
const err = new InternalServerError('There was a database failure, SQL err code %s')
.withErrorType('DATABASE_FAILURE')
.withErrorCode('ERR_INT_500')
.withErrorSubCode('DB_0001')
.withStatusCode(500)
console.log(err.formatMessage('SQL_1234').toJSON())
```
# Error Registry

@@ -150,0 +204,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc