UNPKG

@cerbos/core

Version:
83 lines 2.43 kB
import { setErrorNameAndStack } from "../internal.js"; import { Status } from "../types/external.js"; /** * Error thrown when the Cerbos policy decision point server returns an unsuccessful response. */ export class NotOK extends Error { code; details; /** @deprecated */ static fromJSON(text) { try { const error = JSON.parse(text); return new NotOK(code(error), details(error)); } catch { return new NotOK(Status.UNKNOWN, text); } } /** @internal */ constructor( /** * The status code returned by the Cerbos policy decision point server. */ code, /** * Additional error details. */ details, options) { super(`gRPC error ${code} (${Status[code]}): ${details}`, options); this.code = code; this.details = details; setErrorNameAndStack(this); } } function code(error) { if (has(error, "code") && typeof error.code === "number" && error.code in Status) { return error.code || Status.UNKNOWN; } throw new Error("Error does not include expected code"); } function details(error) { if (has(error, "message") && typeof error.message === "string") { return error.message; } throw new Error("Error does not include expected details"); } function has(object, property) { return !!object && Object.prototype.hasOwnProperty.call(object, property); } /** * Error thrown when input fails schema validation, if the {@link Client} is configured with {@link Options.onValidationError | onValidationError} set to `"throw"`. */ export class ValidationFailed extends Error { validationErrors; /** @internal */ constructor( /** * The validation errors that occurred. */ validationErrors) { super("Input failed schema validation"); this.validationErrors = validationErrors; setErrorNameAndStack(this); } } /** * Error thrown when disabling or deleting a policy violates the integrity of the store. */ export class PolicyStoreIntegrityViolated extends NotOK { violations; /** @internal */ constructor(code, message, /** * Details of the integrity violations for each policy ID. */ violations, options) { super(code, message, options); this.violations = violations; } } //# sourceMappingURL=external.js.map