All files / src/client-side-encryption errors.ts

100% Statements 21/21
100% Branches 1/1
100% Functions 11/11
100% Lines 21/21

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142  432x           432x                         87643x       6917x                 432x                         2192x       356x             432x                           80x 80x       8x               432x                           272x 272x       8x               432x                             1004x 1004x       36x         432x   4x      
import { type Document } from '../bson';
import { MongoError } from '../error';
 
/**
 * @public
 * An error indicating that something went wrong specifically with MongoDB Client Encryption
 */
export class MongoCryptError extends MongoError {
  /**
   * **Do not use this constructor!**
   *
   * Meant for internal use only.
   *
   * @remarks
   * This class is only meant to be constructed within the driver. This constructor is
   * not subject to semantic versioning compatibility guarantees and may change at any time.
   *
   * @public
   **/
  constructor(message: string, options: { cause?: Error } = {}) {
    super(message, options);
  }
 
  override get name() {
    return 'MongoCryptError';
  }
}
 
/**
 * @public
 *
 * An error indicating an invalid argument was provided to an encryption API.
 */
export class MongoCryptInvalidArgumentError extends MongoCryptError {
  /**
   * **Do not use this constructor!**
   *
   * Meant for internal use only.
   *
   * @remarks
   * This class is only meant to be constructed within the driver. This constructor is
   * not subject to semantic versioning compatibility guarantees and may change at any time.
   *
   * @public
   **/
  constructor(message: string) {
    super(message);
  }
 
  override get name() {
    return 'MongoCryptInvalidArgumentError';
  }
}
/**
 * @public
 * An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create data keys
 */
export class MongoCryptCreateDataKeyError extends MongoCryptError {
  encryptedFields: Document;
  /**
   * **Do not use this constructor!**
   *
   * Meant for internal use only.
   *
   * @remarks
   * This class is only meant to be constructed within the driver. This constructor is
   * not subject to semantic versioning compatibility guarantees and may change at any time.
   *
   * @public
   **/
  constructor(encryptedFields: Document, { cause }: { cause: Error }) {
    super(`Unable to complete creating data keys: ${cause.message}`, { cause });
    this.encryptedFields = encryptedFields;
  }
 
  override get name() {
    return 'MongoCryptCreateDataKeyError';
  }
}
 
/**
 * @public
 * An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create a collection
 */
export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError {
  encryptedFields: Document;
  /**
   * **Do not use this constructor!**
   *
   * Meant for internal use only.
   *
   * @remarks
   * This class is only meant to be constructed within the driver. This constructor is
   * not subject to semantic versioning compatibility guarantees and may change at any time.
   *
   * @public
   **/
  constructor(encryptedFields: Document, { cause }: { cause: Error }) {
    super(`Unable to create collection: ${cause.message}`, { cause });
    this.encryptedFields = encryptedFields;
  }
 
  override get name() {
    return 'MongoCryptCreateEncryptedCollectionError';
  }
}
 
/**
 * @public
 * An error indicating that mongodb-client-encryption failed to auto-refresh Azure KMS credentials.
 */
export class MongoCryptAzureKMSRequestError extends MongoCryptError {
  /** The body of the http response that failed, if present. */
  body?: Document;
  /**
   * **Do not use this constructor!**
   *
   * Meant for internal use only.
   *
   * @remarks
   * This class is only meant to be constructed within the driver. This constructor is
   * not subject to semantic versioning compatibility guarantees and may change at any time.
   *
   * @public
   **/
  constructor(message: string, body?: Document) {
    super(message);
    this.body = body;
  }
 
  override get name(): string {
    return 'MongoCryptAzureKMSRequestError';
  }
}
 
/** @public */
export class MongoCryptKMSRequestNetworkTimeoutError extends MongoCryptError {
  override get name(): string {
    return 'MongoCryptKMSRequestNetworkTimeoutError';
  }
}