const decodingErrorDefinitions = {
    UnsupportedTopic: {
        message: "This topic is not supported by the current decoder.",
    },
    NotInSecureContext: {
        message: "This stream requires a secure context such as HTTPS or localhost.",
    },
    EncodedStreamNotSupported: {
        message: "Encoded stream decoding is not supported in this browser.",
    },
    DecoderError: {
        message: "The stream could not be decoded.",
    },
};
export class DecodingError extends Error {
    topicName;
    code;
    constructor(code, topicName, message) {
        super(message ?? decodingErrorDefinitions[code].message);
        this.name = "DecodingError";
        this.code = code;
        this.topicName = topicName;
        Object.setPrototypeOf(this, new.target.prototype);
    }
}
export class UnsupportedTopicError extends DecodingError {
    constructor(topicName, message) {
        super("UnsupportedTopic", topicName, message);
        this.name = "UnsupportedTopicError";
    }
}
export class NotInSecureContextError extends DecodingError {
    constructor(topicName) {
        super("NotInSecureContext", topicName);
        this.name = "NotInSecureContextError";
    }
}
export class EncodedStreamNotSupportedError extends DecodingError {
    constructor(topicName) {
        super("EncodedStreamNotSupported", topicName);
        this.name = "EncodedStreamNotSupportedError";
    }
}
export class DecoderRuntimeError extends DecodingError {
    constructor(topicName, message) {
        super("DecoderError", topicName, message);
        this.name = "DecoderRuntimeError";
    }
}
export function createDecodingError(code, topicName, message) {
    switch (code) {
        case "UnsupportedTopic":
            return new UnsupportedTopicError(topicName, message);
        case "NotInSecureContext":
            return new NotInSecureContextError(topicName);
        case "EncodedStreamNotSupported":
            return new EncodedStreamNotSupportedError(topicName);
        case "DecoderError":
            return new DecoderRuntimeError(topicName, message);
        default:
            return new DecoderRuntimeError(topicName, message ?? `Unexpected decoding error code: ${String(code)}`);
    }
}
//# sourceMappingURL=error.js.map