shelving 1.133.0 → 1.134.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Error with a `.code` field and a `.details` field to provide context about what went wrong.
3
+ * - Code should be a `number` in the range of 400-599
4
+ * - Details are appended to `.message` in the format `message: debuggedContext`
5
+ * - Details are converted to string using `debug()`
6
+ */
7
+ export declare class CodedError extends Error {
8
+ /** Number in the range of 400-599, roughly corresponding to HTTP error codes. */
9
+ readonly code: number;
10
+ /** Details about the error, which are appended to the message. */
11
+ readonly details: unknown;
12
+ constructor(message?: string, details?: unknown);
13
+ }
@@ -0,0 +1,21 @@
1
+ import { debug } from "../util/debug.js";
2
+ /**
3
+ * Error with a `.code` field and a `.details` field to provide context about what went wrong.
4
+ * - Code should be a `number` in the range of 400-599
5
+ * - Details are appended to `.message` in the format `message: debuggedContext`
6
+ * - Details are converted to string using `debug()`
7
+ */
8
+ export class CodedError extends Error {
9
+ /** Number in the range of 400-599, roughly corresponding to HTTP error codes. */
10
+ code = 500;
11
+ /** Details about the error, which are appended to the message. */
12
+ details;
13
+ constructor(message = CodedError.prototype.message, details) {
14
+ const debugged = details !== undefined ? debug(details, 2) : "";
15
+ super(debugged.length ? `${message}: ${debugged}` : message);
16
+ this.details = details;
17
+ Error.captureStackTrace(this, CodedError);
18
+ }
19
+ }
20
+ CodedError.prototype.name = "CodedError";
21
+ CodedError.prototype.message = "Internal error";
@@ -1,6 +1,6 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if the state of the program is not correct to execute a given operation. */
3
- export declare class ConflictError extends EnhancedError {
3
+ export declare class ConflictError extends CodedError {
4
4
  readonly code = 509;
5
5
  constructor(message?: string, context?: unknown);
6
6
  }
@@ -1,9 +1,11 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if the state of the program is not correct to execute a given operation. */
3
- export class ConflictError extends EnhancedError {
3
+ export class ConflictError extends CodedError {
4
4
  code = 509;
5
- constructor(message = "Conflict", context) {
5
+ constructor(message = ConflictError.prototype.message, context) {
6
6
  super(message, context);
7
+ Error.captureStackTrace(this, ConflictError);
7
8
  }
8
9
  }
9
10
  ConflictError.prototype.name = "ConflictError";
11
+ ConflictError.prototype.message = "Conflict";
@@ -1,5 +1,5 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if e.g. a user's internet connection fails. */
3
- export declare class ConnectionError extends EnhancedError {
3
+ export declare class ConnectionError extends CodedError {
4
4
  constructor(message?: string, context?: unknown);
5
5
  }
@@ -1,8 +1,10 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if e.g. a user's internet connection fails. */
3
- export class ConnectionError extends EnhancedError {
4
- constructor(message = "Connection error", context) {
3
+ export class ConnectionError extends CodedError {
4
+ constructor(message = ConnectionError.prototype.message, context) {
5
5
  super(message, context);
6
+ Error.captureStackTrace(this, ConnectionError);
6
7
  }
7
8
  }
8
9
  ConnectionError.prototype.name = "ConnectionError";
10
+ ConnectionError.prototype.message = "Connection error";
@@ -1,6 +1,6 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if an operation failed because the user is logged in but does not have sufficient privileges to access something. */
3
- export declare class ForbiddenError extends EnhancedError {
3
+ export declare class ForbiddenError extends CodedError {
4
4
  readonly code = 403;
5
5
  constructor(message?: string, context?: unknown);
6
6
  }
@@ -1,9 +1,11 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if an operation failed because the user is logged in but does not have sufficient privileges to access something. */
3
- export class ForbiddenError extends EnhancedError {
3
+ export class ForbiddenError extends CodedError {
4
4
  code = 403;
5
- constructor(message = "Forbidden", context) {
5
+ constructor(message = ForbiddenError.prototype.message, context) {
6
6
  super(message, context);
7
+ Error.captureStackTrace(this, ForbiddenError);
7
8
  }
8
9
  }
9
10
  ForbiddenError.prototype.name = "ForbiddenError";
11
+ ForbiddenError.prototype.message = "Forbidden";
@@ -1,6 +1,6 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if if a value is required but doesn't exist. */
3
- export declare class NotFoundError extends EnhancedError {
3
+ export declare class NotFoundError extends CodedError {
4
4
  readonly code = 404;
5
5
  constructor(message?: string, context?: unknown);
6
6
  }
@@ -1,9 +1,11 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if if a value is required but doesn't exist. */
3
- export class NotFoundError extends EnhancedError {
3
+ export class NotFoundError extends CodedError {
4
4
  code = 404;
5
- constructor(message = "Not found", context) {
5
+ constructor(message = NotFoundError.prototype.message, context) {
6
6
  super(message, context);
7
+ Error.captureStackTrace(this, NotFoundError);
7
8
  }
8
9
  }
9
10
  NotFoundError.prototype.name = "NotFoundError";
11
+ NotFoundError.prototype.message = "Not found";
@@ -1,6 +1,6 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Error thrown when functionality is called but is not implemented by an interface. */
3
- export declare class NotImplementedError extends EnhancedError {
3
+ export declare class NotImplementedError extends CodedError {
4
4
  readonly code = 501;
5
5
  constructor(message?: string, value?: unknown);
6
6
  }
@@ -1,9 +1,11 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Error thrown when functionality is called but is not implemented by an interface. */
3
- export class NotImplementedError extends EnhancedError {
3
+ export class NotImplementedError extends CodedError {
4
4
  code = 501;
5
- constructor(message = "Not implemented", value) {
5
+ constructor(message = NotImplementedError.prototype.message, value) {
6
6
  super(message, value);
7
+ Error.captureStackTrace(this, NotImplementedError);
7
8
  }
8
9
  }
9
10
  NotImplementedError.prototype.name = "NotImplementedError";
11
+ NotImplementedError.prototype.message = "Not implemented";
@@ -1,6 +1,6 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if an operation failed because the user is logged in but does not have sufficient privileges to access something. */
3
- export declare class UnauthorizedError extends EnhancedError {
3
+ export declare class UnauthorizedError extends CodedError {
4
4
  readonly code = 401;
5
5
  constructor(message?: string, context?: unknown);
6
6
  }
@@ -1,9 +1,11 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Thrown if an operation failed because the user is logged in but does not have sufficient privileges to access something. */
3
- export class UnauthorizedError extends EnhancedError {
3
+ export class UnauthorizedError extends CodedError {
4
4
  code = 401;
5
- constructor(message = "Unauthorized", context) {
5
+ constructor(message = UnauthorizedError.prototype.message, context) {
6
6
  super(message, context);
7
+ Error.captureStackTrace(this, UnauthorizedError);
7
8
  }
8
9
  }
9
10
  UnauthorizedError.prototype.name = "UnauthorizedError";
11
+ UnauthorizedError.prototype.message = "Unauthorized";
@@ -1,6 +1,6 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Error thrown when a value isn't valid. */
3
- export declare class ValidationError extends EnhancedError {
3
+ export declare class ValidationError extends CodedError {
4
4
  readonly code = 422;
5
5
  constructor(message?: string, context?: unknown);
6
6
  }
@@ -1,9 +1,11 @@
1
- import { EnhancedError } from "./EnhancedError.js";
1
+ import { CodedError } from "./CodedError.js";
2
2
  /** Error thrown when a value isn't valid. */
3
- export class ValidationError extends EnhancedError {
3
+ export class ValidationError extends CodedError {
4
4
  code = 422;
5
- constructor(message = "Invalid value", context) {
5
+ constructor(message = ValidationError.prototype.message, context) {
6
6
  super(message, context);
7
+ Error.captureStackTrace(this, ValidationError);
7
8
  }
8
9
  }
9
10
  ValidationError.prototype.name = "ValidationError";
11
+ ValidationError.prototype.message = "Invalid input";
package/error/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./EnhancedError.js";
1
+ export * from "./CodedError.js";
2
2
  export * from "./ConflictError.js";
3
3
  export * from "./ConnectionError.js";
4
4
  export * from "./ForbiddenError.js";
package/error/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./EnhancedError.js";
1
+ export * from "./CodedError.js";
2
2
  export * from "./ConflictError.js";
3
3
  export * from "./ConnectionError.js";
4
4
  export * from "./ForbiddenError.js";
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.133.0",
14
+ "version": "1.134.1",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -1,10 +0,0 @@
1
- /**
2
- * Error with a `.context` field to provide information about what went wrong.
3
- * - Context is appended to `.message` in the format `message: debuggedContext`
4
- * - Context is converted to a string using `debug()`
5
- */
6
- export declare class EnhancedError extends Error {
7
- readonly code: number;
8
- readonly context: unknown;
9
- constructor(message: string, context?: unknown);
10
- }
@@ -1,16 +0,0 @@
1
- import { debug } from "../util/debug.js";
2
- /**
3
- * Error with a `.context` field to provide information about what went wrong.
4
- * - Context is appended to `.message` in the format `message: debuggedContext`
5
- * - Context is converted to a string using `debug()`
6
- */
7
- export class EnhancedError extends Error {
8
- code = 500;
9
- context;
10
- constructor(message, context) {
11
- const debugged = context !== undefined ? debug(context, 2) : "";
12
- super(debugged.length ? `${message}: ${debugged}` : message);
13
- this.context = context;
14
- }
15
- }
16
- EnhancedError.prototype.name = "EnhancedError";
@@ -1,7 +0,0 @@
1
- /**
2
- * Thrown to wrap an error with another error.
3
- * - Merges the message and stack of the previous message.
4
- */
5
- export declare class ThroughError extends Error {
6
- constructor(message: string, cause: unknown);
7
- }
@@ -1,13 +0,0 @@
1
- import { debug } from "../util/debug.js";
2
- /**
3
- * Thrown to wrap an error with another error.
4
- * - Merges the message and stack of the previous message.
5
- */
6
- export class ThroughError extends Error {
7
- constructor(message, cause) {
8
- super(message);
9
- this.cause = cause;
10
- this.stack = `${this.stack || ""}\nCause: ${cause instanceof Error ? cause.stack || "" : debug(cause)}`;
11
- }
12
- }
13
- ThroughError.prototype.name = "ThroughError";