unierror.uts 1.5 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1
import {ConnectSocketFail, SendSocketMessageFail ,ConnectSocketErrorCode, SendSocketMessageErrorCode} from "./interface.uts"
DCloud-yyl's avatar
DCloud-yyl 已提交
2 3 4 5 6 7 8 9 10

/**
 * 错误主题
 */
export const UniErrorSubject = 'uni-websocket';
/**
 * 错误码
 * @UniError
 */
DCloud-yyl's avatar
DCloud-yyl 已提交
11
export const ConnectUniErrors : Map<ConnectSocketErrorCode, string> = new Map([
DCloud-yyl's avatar
DCloud-yyl 已提交
12 13 14
	/**
	 * URL 格式不合法
	 */
DCloud-yyl's avatar
DCloud-yyl 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	[600009, 'invalid URL'],
]);


/**
 * 错误码
 * @UniError
 */
export const SendMessageUniErrors : Map<SendSocketMessageErrorCode, string> = new Map([
	/**
	 * 发送数据超限,发送队列不能超过16M大小。
	 */
	[10001, 'The queue memory exceeds 16 MiB and the connection will be closed'],
	/**
	 * websocket未连接
	 */
	[10002, 'webSocket is not connected'],
	/**
	 * request系统错误
	 */
	[602001, 'websocket system error']
DCloud-yyl's avatar
DCloud-yyl 已提交
36 37 38
]);


DCloud-yyl's avatar
DCloud-yyl 已提交
39 40 41 42
export class ConnectSocketFailImpl extends UniError implements ConnectSocketFail {
// #ifdef APP-ANDROID
	override errCode: ConnectSocketErrorCode
// #endif
DCloud-yyl's avatar
DCloud-yyl 已提交
43 44 45 46
	constructor(errCode : ConnectSocketErrorCode) {
		super();
		this.errSubject = UniErrorSubject;
		this.errCode = errCode;
DCloud-yyl's avatar
DCloud-yyl 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59
		this.errMsg = ConnectUniErrors[errCode] ?? ""
	}
}

export class SendSocketMessageFailImpl extends UniError implements SendSocketMessageFail {
// #ifdef APP-ANDROID
	override errCode: SendSocketMessageErrorCode
// #endif
	constructor(errCode : SendSocketMessageErrorCode) {
		super();
		this.errSubject = UniErrorSubject;
		this.errCode = errCode;
		this.errMsg = SendMessageUniErrors[errCode] ?? ""
DCloud-yyl's avatar
DCloud-yyl 已提交
60 61
	}
}