export class UmbError extends Error {
    constructor() {
        super(...arguments);
        this.name = 'UmbError';
    }
    static isUmbError(error) {
        return error instanceof UmbError || error.name === 'UmbError';
    }
}
export class UmbCancelError extends UmbError {
    constructor() {
        super(...arguments);
        this.name = 'UmbCancelError';
    }
    static isUmbCancelError(error) {
        return error instanceof UmbCancelError || error.name === 'UmbCancelError';
    }
    /**
     * Transforms a CancelError into an UmbCancelError.
     * @param {*} error The CancelError to transform.
     * @returns {UmbCancelError} The transformed UmbCancelError.
     * @deprecated Use `UmbCancelError.isUmbCancelError` instead and map your object to `UmbCancelError` if needed.
     */
    static fromLegacyCancelError(error) {
        return new UmbCancelError(error.message);
    }
}
/**
 * UmbApiError is a class that extends UmbError and represents an error that occurs during an API call.
 */
export class UmbApiError extends UmbError {
    constructor(message, status, request, problemDetails) {
        super(message);
        this.name = 'UmbApiError';
        this.status = status;
        this.request = request;
        this.problemDetails = problemDetails;
    }
    static isUmbApiError(error) {
        return error instanceof UmbApiError || error.name === 'UmbApiError';
    }
    /**
     * Transforms an ApiError into an UmbApiError.
     * @param {*} error The ApiError to transform.
     * @returns {UmbApiError} The transformed UmbApiError.
     * @deprecated Use `UmbCancelError.isUmbApiError` instead and map your object to `UmbApiError` if needed.
     */
    static fromLegacyApiError(error) {
        // ApiError - body could hold a ProblemDetails from the server
        let problemDetails = null;
        if (typeof error.body !== 'undefined' && !!error.body) {
            try {
                problemDetails = typeof error.body === 'string' ? JSON.parse(error.body) : error.body;
            }
            catch (e) {
                console.error('Error parsing error body (expected JSON)', e);
            }
        }
        return new UmbApiError(error.message, error.status ?? 0, error.request, problemDetails ?? { title: error.message, type: 'ApiError', status: error.status ?? 0 });
    }
}
