UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

35 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DonobuException = void 0; class DonobuException extends Error { constructor(userFacingMessage, internalMessage, httpCode = 400) { super(internalMessage || userFacingMessage); // Pass the internal message to the base Error class this.userFacingMessage = userFacingMessage; this.internalMessage = internalMessage; this.httpCode = httpCode; this.userFacingMessage = userFacingMessage; this.internalMessage = internalMessage || userFacingMessage; this.httpCode = httpCode; this.donobuErrorCode = this.divineErrorCodeFromClassName(); // Ensure the prototype chain is maintained Object.setPrototypeOf(this, new.target.prototype); } /** * Constructs a Donobu error code from the name of the underlying class. * Converts the class name to UPPER_SNAKE_CASE and removes the "Exception" suffix. */ divineErrorCodeFromClassName() { const className = this.constructor.name; if (!className) { throw new Error('Unable to determine error code from class name.'); } // Convert CamelCase to UPPER_SNAKE_CASE const upperSnakeCase = className .replace(/([a-z])([A-Z])/g, '$1_$2') // Insert underscores between camelCase .toUpperCase() .replace(/_EXCEPTION$/, ''); // Remove "_EXCEPTION" if present return upperSnakeCase; } } exports.DonobuException = DonobuException; //# sourceMappingURL=DonobuException.js.map