import { SerializableError } from '../../models/SerializableError.js';
export class ApiError {
    name = 'ApiError';
    code;
    message;
    detail;
    constructor(messageOrInit, code) {
        if (typeof messageOrInit === 'string') {
            if (typeof code === 'number') {
                this.code = code;
            }
            else {
                this.code = 0;
            }
            this.message = messageOrInit;
        }
        else {
            this.message = messageOrInit.message;
            this.code = messageOrInit.code;
            if (messageOrInit.detail) {
                this.detail = messageOrInit.detail;
            }
        }
    }
    toJSON() {
        const { message, code, detail } = this;
        const result = {
            error: true,
            message,
            code,
        };
        if (detail) {
            result.detail = detail;
        }
        return result;
    }
    toString() {
        return this.message;
    }
}
export class SdkError extends SerializableError {
    /**
     * The raw response from the server.
     */
    response;
    /**
     * Optional detailed message returned by the server.
     */
    detail;
    toJSON() {
        const result = super.toJSON();
        if (this.response) {
            result.response = this.response;
        }
        if (this.detail) {
            result.detail = this.detail;
        }
        return result;
    }
}
//# sourceMappingURL=Errors.js.map