/*!
 * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
 */
import { Exception } from '@webex/common';
export class ConnectionError extends Exception {
    static defaultMessage = 'Failed to connect to socket';
    code;
    reason;
    constructor(event = {}) {
        super(event);
        this.code = event.code;
        this.reason = event.reason;
    }
    parse(event = {}) {
        return event.reason;
    }
}
export class UnknownResponse extends ConnectionError {
    static defaultMessage = 'UnknownResponse is produced by IE when we receive a 4XXX. You probably want to treat this like a NotFound';
    constructor(event) {
        super(event);
    }
}
export class BadRequest extends ConnectionError {
    static defaultMessage = 'BadRequest usually implies an attempt to use service account credentials';
    constructor(event) {
        super(event);
    }
}
export class NotAuthorized extends ConnectionError {
    static defaultMessage = 'Please refresh your access token';
    constructor(event) {
        super(event);
    }
}
export class Forbidden extends ConnectionError {
    static defaultMessage = 'Forbidden usually implies these credentials are not entitled for Webex';
    constructor(event) {
        super(event);
    }
}
export function createWssResponseError(response, statusCode, statusMessage) {
    const error = new Error(statusMessage || `Mobius websocket request failed with status ${statusCode || 'unknown'}`);
    error.name = 'MobiusSocketResponseError';
    error.statusCode = statusCode;
    error.statusMessage = statusMessage;
    error.response = response;
    error.trackingId = response?.trackingId;
    return error;
}
export function createTimeoutError(request) {
    const errorPayload = {
        type: 'response_event',
        subtype: request.type,
        trackingId: request.trackingId,
    };
    return createWssResponseError(errorPayload, 408, 'Mobius websocket response timed out');
}
