/* tslint:disable:max-classes-per-file */ import { RPCFailurePayload } from '../types' export class ClientError extends Error { constructor (name: string, message: string) { super() this.name = name this.message = message } } export class ClientInitializeError extends ClientError { constructor () { super('ClientInitializeError', 'Client was not properly initialized') } } export class ConnectionError extends ClientError { public error: any constructor (error: any) { super('ConnectionError', 'Client attempted to connect with configuration and failed') Object.assign(this, error) } } export class PublishError extends ClientError { public error: any public payload: string constructor (topic: string, payload: string, error: any) { super('PublishError', `Failed to publish payload to ${topic}`) this.payload = payload Object.assign(this, error) } } export class SubscribeError extends ClientError { public error: any public topic: string constructor (topic: string, error: any) { super('SubscribeError', `Failed to subscribe to ${topic}`) this.topic = topic Object.assign(this, error) } } export class UnsubscribeError extends ClientError { public error: any public topic: string constructor (topic: string, error: any) { super('UnsubscribeError', `Failed to unsubscribe from ${topic}`) this.topic = topic Object.assign(this, error) } } export class RequestTimeoutError extends ClientError { public timeout: number constructor (timeout: number) { super('RequestTimeoutError', `No response after ${timeout} ms`) this.timeout = timeout } } export class ListenerCleanUpError extends ClientError { public error: any constructor (error: any) { super('ListenerCleanUpError', 'An error occurred while cleaning up event listeners') Object.assign(this, error) } } export class InvalidMessageError extends ClientError { public topic: string public payload: string constructor (topic: string, payload: string) { super('InvalidMessageError', 'Received invalid JSON in message') this.topic = topic this.payload = payload } } export class MessageProcessorError extends ClientError { public error: any constructor (error: any) { super('MessageProcessorError', 'An error occurred when receiving a message') Object.assign(this, error) } } export class RPCResponseError extends ClientError { public requestId: string public code: number constructor (payload: RPCFailurePayload) { super('RPCResponseError', payload.error.message) const { requestId, error, } = payload this.requestId = requestId this.code = error.code } } export class NoDeviceTypeError extends ClientError { constructor () { super('NoDeviceTypeError', 'Could not commission device due to missing productId in client config') } } export class ClientNotConnectedError extends ClientError { constructor () { super('ClientNotConnectedError', 'Client is not connected, could not perform operation') } } export class CommissionError extends ClientError { public error: any constructor (error: any) { super('CommissionError', 'Failed to commission device') Object.assign(this, error) } } export class DecommissionError extends ClientError { public error: any constructor (error: any) { super('DecommissionError', 'Failed to decommission device') Object.assign(this, error) } } export class GetDeviceInfoError extends ClientError { public error: any constructor (error: any) { super('GetDeviceInfo', 'Failed to get device information') Object.assign(this, error) } } export class GetProductInfoError extends ClientError { public error: any constructor (error: any) { super('GetProductInfo', 'Failed to get product information') Object.assign(this, error) } } export class AssociateUserError extends ClientError { public error: any constructor (error: any) { super('AssociateUser', 'Failed to associate a user to a device') Object.assign(this, error) } } export class GetInvitationCodeError extends ClientError { public error: any constructor (error: any) { super('GetInvitationCodeError', 'Failed to get invitation code') Object.assign(this, error) } } export class GetStateError extends ClientError { public error: any constructor (error: any) { super('GetStateError', 'Failed to get device state') Object.assign(this, error) } } export class SetStateError extends ClientError { public error: any constructor (error: any) { super('SetStateError', 'Failed to set device state') Object.assign(this, error) } } export class GetStatusError extends ClientError { public error: any constructor (error: any) { super('GetStatusError', 'Failed to get device status') Object.assign(this, error) } } export class CreateAndPairError extends ClientError { public error: any constructor (error: any) { super('CreateAndPairError', 'Failed to create and pair a child device') Object.assign(this, error) } } export class PairChildError extends ClientError { public error: any constructor (deviceId: string, error: any) { super('CreateAndPairError', `Failed to create and pair a child device ${deviceId}`) Object.assign(this, error) } } export class ListChildrenError extends ClientError { public error: any constructor (error: any) { super('ListChildrenError', 'Failed to list children') Object.assign(this, error) } } export class RemoveChildError extends ClientError { public error: any constructor (error: any) { super('RemoveChildError', 'Failed to remove child') Object.assign(this, error) } } export class GetFirmwareError extends ClientError { public error: any constructor (error: any) { super('GetFirmwareError', 'Failed to get firmware') Object.assign(this, error) } }