You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.6 KiB
91 lines
2.6 KiB
|
5 months ago
|
import {
|
||
|
|
ERROR_NAME_ALREADY_EXISTS,
|
||
|
|
ERROR_NAME_CHANNEL_ALREADY_EXISTS,
|
||
|
|
ERROR_NAME_CHANNEL_NOT_FOUND,
|
||
|
|
ERROR_NAME_DISPOSED,
|
||
|
|
ERROR_NAME_INVALID_FRAME,
|
||
|
|
ERROR_NAME_INVALID_NAME,
|
||
|
|
ERROR_NAME_NOT_FOUND
|
||
|
|
} from './consts.ts';
|
||
|
|
|
||
|
|
abstract class ConnEngineError extends Error {
|
||
|
|
abstract readonly name: string;
|
||
|
|
constructor(message: string, options?: { cause?: unknown }) {
|
||
|
|
super(message, options);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnDisposedError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_DISPOSED;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnConnectionAlreadyExistsError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_ALREADY_EXISTS;
|
||
|
|
readonly connection: string;
|
||
|
|
constructor(message: string, connection: string) {
|
||
|
|
super(message);
|
||
|
|
this.connection = connection;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnConnectionNotFoundError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_NOT_FOUND;
|
||
|
|
readonly connection: string;
|
||
|
|
constructor(message: string, connection: string) {
|
||
|
|
super(message);
|
||
|
|
this.connection = connection;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnInvalidConnectionNameError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_INVALID_NAME;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnInvalidFrameError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_INVALID_FRAME;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnChannelAlreadyExistsError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_CHANNEL_ALREADY_EXISTS;
|
||
|
|
readonly channel: string;
|
||
|
|
constructor(message: string, channel: string) {
|
||
|
|
super(message);
|
||
|
|
this.channel = channel;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ConnChannelNotFoundError extends ConnEngineError {
|
||
|
|
readonly name = ERROR_NAME_CHANNEL_NOT_FOUND;
|
||
|
|
readonly channel: string;
|
||
|
|
constructor(message: string, channel: string) {
|
||
|
|
super(message);
|
||
|
|
this.channel = channel;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isConnDisposedError(value: unknown): value is ConnDisposedError {
|
||
|
|
return value instanceof Error && (value as { name?: string }).name === ERROR_NAME_DISPOSED;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isConnConnectionAlreadyExistsError(
|
||
|
|
value: unknown
|
||
|
|
): value is ConnConnectionAlreadyExistsError {
|
||
|
|
return value instanceof Error && (value as { name?: string }).name === ERROR_NAME_ALREADY_EXISTS;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isConnConnectionNotFoundError(
|
||
|
|
value: unknown
|
||
|
|
): value is ConnConnectionNotFoundError {
|
||
|
|
return value instanceof Error && (value as { name?: string }).name === ERROR_NAME_NOT_FOUND;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isConnInvalidConnectionNameError(
|
||
|
|
value: unknown
|
||
|
|
): value is ConnInvalidConnectionNameError {
|
||
|
|
return value instanceof Error && (value as { name?: string }).name === ERROR_NAME_INVALID_NAME;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isConnInvalidFrameError(value: unknown): value is ConnInvalidFrameError {
|
||
|
|
return value instanceof Error && (value as { name?: string }).name === ERROR_NAME_INVALID_FRAME;
|
||
|
|
}
|