@datastax/astra-db-ts
Version:
Data API TypeScript client
31 lines (30 loc) • 1.09 kB
JavaScript
// Copyright Datastax, Inc
// SPDX-License-Identifier: Apache-2.0
// noinspection ExceptionCaughtLocallyJS
import { betterTypeOf } from '../documents/utils.js';
import { jsonTryStringify } from '../lib/utils.js';
export class NonErrorError extends Error {
constructor(value) {
const valueType = betterTypeOf(value);
try {
const valueString = jsonTryStringify(value, `${value}`);
super(`Non-error value thrown; type='${valueType}' toString='${value}' JSON.stringified='${valueString}'`);
Object.defineProperty(this, "value", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
catch (_) {
super(`Non-error value thrown; type='${valueType}'`); // catch to prevent property tests from failing if obj toString is not a function
}
this.value = value;
}
static asError(e) {
if (e instanceof Error) {
return e;
}
return new NonErrorError(e);
}
}