All files / src/errors base-error.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                  6169x 6169x      
/** Driver error object as produced by `pg` (a subset of its fields). */
export type DriverError = Error &
  Readonly<{
    /** SQLSTATE or Node.js error code. */
    code?: string;
    /** Error detail reported by PostgreSQL. */
    detail?: string;
    /** Table the error refers to. */
    table?: string;
    /** Constraint the error refers to. */
    constraint?: string;
    /** Schema the error refers to. */
    schema?: string;
    /** Column the error refers to. */
    column?: string;
  }>;
 
/**
 * Root of the error hierarchy, so one `instanceof` check catches every error postgrelize throws (Sequelize v6 `BaseError`).
 *
 * Programmer mistakes (such as committing a finished transaction) still throw a plain `Error`.
 *
 * @example
 * ```ts
 * try {
 *   await User.findOne({ where: { id: 1 }, rejectOnEmpty: true });
 * } catch (e) {
 *   if (e instanceof BaseError) {
 *     console.error(e.name, e.message);
 *   }
 * }
 * ```
 */
export class BaseError extends Error {
  /**
   * Creates the error and sets `name` to `'SequelizeBaseError'`.
   *
   * @param message - Error message.
   * @param options - Standard error options (`cause`).
   */
  constructor(message?: string, options?: ErrorOptions) {
    super(message, options);
    this.name = 'SequelizeBaseError';
  }
}