@maximai/maxim-js
Version:
Maxim AI JS SDK. Visit https://getmaxim.ai for more info.
74 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Error = void 0;
const base_1 = require("./base");
const types_1 = require("./types");
/**
* Represents an error or exception that occurred within the trace.
*
* The Error class captures detailed information about failures, exceptions,
* and error conditions, providing context for debugging and monitoring.
*
* @class Error
* @extends BaseContainer
* @example
* const error = container.error({
* id: 'err-001',
* message: 'Failed to connect to external API',
* code: 'CONNECTION_TIMEOUT',
* type: 'NetworkError',
* });
*
* @example
* // Capturing JavaScript errors
* try {
* await riskyOperation();
* } catch (err) {
* const error = container.error({
* id: 'operation-failure',
* message: err.message,
* name: err.name,
* type: 'JavaScriptError',
* });
* }
*/
class Error extends base_1.BaseContainer {
/**
* Creates a new error log entry.
*
* @param config - Configuration object defining the error details
* @param writer - Log writer instance for persisting the error
* @example
* const error = container.error({
* id: 'validation-error',
* message: 'Invalid input parameters',
* code: 'VALIDATION_FAILED',
* type: 'ValidationError',
* });
*/
constructor(config, writer) {
super(types_1.Entity.ERROR, config, writer);
this.message = config.message;
this.code = config.code;
this.errorType = config.type;
this.name = config.name;
}
/**
* Returns the complete data representation of this error.
*
* @returns Error data
* @example
* const errorData = error.data();
*/
data() {
return {
...super.data(),
message: this.message,
code: this.code,
errorType: this.errorType,
name: this.name,
};
}
}
exports.Error = Error;
//# sourceMappingURL=error.js.map