@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
84 lines (82 loc) • 2.11 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 1.0.3
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class SdkError extends Error {
static {
__name(this, "SdkError");
}
code;
_status;
timestamp;
originalError;
constructor(params) {
const message = SdkError.formatErrorMessage(params);
super(message);
this.name = "SdkError";
this.code = params.code;
this._status = params.status;
this.originalError = params.originalError;
this.timestamp = /* @__PURE__ */ new Date();
this.cleanErrorStack();
}
get status() {
return this._status;
}
/**
* Creates SdkError from exception
*/
static fromException(error, context) {
if (error instanceof SdkError) return error;
return new SdkError({
code: context?.code || "JSSDK_INTERNAL_ERROR",
status: context?.status || 500,
description: error instanceof Error ? error.message : `${error}`,
originalError: error
});
}
/**
* Serializes error for logging and debugging
*/
toJSON() {
return {
name: this.name,
code: this.code,
message: this.message,
status: this._status,
timestamp: this.timestamp.toISOString(),
stack: this.stack
};
}
/**
* Formats error information for human-readable output
*/
toString() {
let output = `[${this.name}] ${this.code} (${this._status}): ${this.message}`;
if (this.stack) {
output += `
Stack trace:
${this.stack}`;
}
return output;
}
static formatErrorMessage(params) {
if (!params?.description) {
return `Internal error`;
}
return `${params.description}`;
}
cleanErrorStack() {
if (typeof this.stack === "string") {
this.stack = this.stack.split("\n").filter((line) => !line.includes("SdkError.constructor")).join("\n");
}
}
}
export { SdkError };
//# sourceMappingURL=sdk-error.mjs.map