UNPKG

@datastax/astra-db-ts

Version:
233 lines (232 loc) 9.11 kB
"use strict"; // Copyright Datastax, Inc // SPDX-License-Identifier: Apache-2.0 var _CollectionInsertManyError_partialResult, _CollectionInsertManyError_causes, _TableInsertManyError_partialResult, _TableInsertManyError_causes; Object.defineProperty(exports, "__esModule", { value: true }); exports.CollectionDeleteManyError = exports.CollectionUpdateManyError = exports.TableInsertManyError = exports.CollectionInsertManyError = exports.DataAPIResponseError = exports.TooManyDocumentsToCountError = exports.DataAPITimeoutError = exports.DataAPIHttpError = exports.DataAPIError = void 0; const tslib_1 = require("tslib"); const timeouts_js_1 = require("../lib/api/timeouts/timeouts.js"); const errors_js_1 = require("../lib/errors.js"); class DataAPIError extends Error { withTransientDupesForEvents() { return this; } } exports.DataAPIError = DataAPIError; class DataAPIHttpError extends DataAPIError { constructor(resp) { super(`HTTP error (${resp.status}): ${resp.body ? resp.body : resp.statusText}`); Object.defineProperty(this, "status", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "body", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "raw", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.status = resp.status; this.body = resp.body; this.raw = resp; this.name = 'DataAPIHttpError'; } } exports.DataAPIHttpError = DataAPIHttpError; class DataAPITimeoutError extends DataAPIError { constructor(info, types) { super(timeouts_js_1.Timeouts.fmtTimeoutMsg(info.timeoutManager, types)); Object.defineProperty(this, "timeout", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "timedOutCategories", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.timeout = info.timeoutManager.initial(); this.timedOutCategories = types; this.name = 'DataAPITimeoutError'; } static mk(info, types) { return new DataAPITimeoutError(info, types); } } exports.DataAPITimeoutError = DataAPITimeoutError; class TooManyDocumentsToCountError extends DataAPIError { constructor(limit, hitServerLimit) { const message = (hitServerLimit) ? `Too many documents to count (server limit of ${limit} reached)` : `Too many documents to count (provided limit is ${limit})`; super(message); Object.defineProperty(this, "limit", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "hitServerLimit", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.limit = limit; this.hitServerLimit = hitServerLimit; this.name = 'TooManyDocumentsToCountError'; } } exports.TooManyDocumentsToCountError = TooManyDocumentsToCountError; class DataAPIResponseError extends DataAPIError { constructor(command, rawResponse) { const errorDescriptors = rawResponse.errors; const message = (errorDescriptors[0]?.message) ? `${errorDescriptors[0].message}${errorDescriptors.length > 1 ? ` (+ ${errorDescriptors.length - 1} more errors)` : ''}` : `Something went wrong (${errorDescriptors.length} errors)`; super(message); Object.defineProperty(this, "command", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "rawResponse", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.name = 'DataAPIResponseError'; this.command = command; this.rawResponse = rawResponse; } get errorDescriptors() { return this.rawResponse.errors; } get warnings() { return this.rawResponse.warnings ?? []; } withTransientDupesForEvents() { return { name: this.name }; } } exports.DataAPIResponseError = DataAPIResponseError; class CollectionInsertManyError extends DataAPIError { constructor(causes, partRes) { super(mkInsertManyErrorMsg(causes)); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'CollectionInsertManyError' }); _CollectionInsertManyError_partialResult.set(this, void 0); _CollectionInsertManyError_causes.set(this, void 0); tslib_1.__classPrivateFieldSet(this, _CollectionInsertManyError_partialResult, partRes, "f"); tslib_1.__classPrivateFieldSet(this, _CollectionInsertManyError_causes, causes, "f"); } insertedIds() { return tslib_1.__classPrivateFieldGet(this, _CollectionInsertManyError_partialResult, "f").insertedIds; } errors() { return tslib_1.__classPrivateFieldGet(this, _CollectionInsertManyError_causes, "f"); } } exports.CollectionInsertManyError = CollectionInsertManyError; _CollectionInsertManyError_partialResult = new WeakMap(), _CollectionInsertManyError_causes = new WeakMap(); class TableInsertManyError extends DataAPIError { constructor(causes, partRes) { super(mkInsertManyErrorMsg(causes)); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'TableInsertManyError' }); _TableInsertManyError_partialResult.set(this, void 0); _TableInsertManyError_causes.set(this, void 0); tslib_1.__classPrivateFieldSet(this, _TableInsertManyError_partialResult, partRes, "f"); tslib_1.__classPrivateFieldSet(this, _TableInsertManyError_causes, causes, "f"); } insertedIds() { return tslib_1.__classPrivateFieldGet(this, _TableInsertManyError_partialResult, "f").insertedIds; } errors() { return tslib_1.__classPrivateFieldGet(this, _TableInsertManyError_causes, "f"); } } exports.TableInsertManyError = TableInsertManyError; _TableInsertManyError_partialResult = new WeakMap(), _TableInsertManyError_causes = new WeakMap(); class CollectionUpdateManyError extends DataAPIError { constructor(cause, partialRes) { const errorCause = errors_js_1.NonErrorError.asError(cause); super(errorCause.message); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'CollectionUpdateManyError' }); Object.defineProperty(this, "partialResult", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "cause", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.partialResult = partialRes; this.cause = errorCause; } } exports.CollectionUpdateManyError = CollectionUpdateManyError; class CollectionDeleteManyError extends DataAPIError { constructor(cause, partialRes) { const errorCause = errors_js_1.NonErrorError.asError(cause); super(errorCause.message); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'CollectionDeleteManyError' }); Object.defineProperty(this, "partialResult", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "cause", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.partialResult = partialRes; this.cause = errorCause; } } exports.CollectionDeleteManyError = CollectionDeleteManyError; function mkInsertManyErrorMsg(causes) { const errorDescriptor = causes[0].errorDescriptors[0]; const numErrors = causes.reduce((acc, e) => acc + e.errorDescriptors.length, 0); return (errorDescriptor?.message) ? `${errorDescriptor.message}${numErrors > 1 ? ` (+ ${numErrors - 1} more errors)` : ''}` : `Something went wrong (${numErrors} errors)`; }