From 2b5e7665ddff4b9a124b25a326a762cd74213b94 Mon Sep 17 00:00:00 2001 From: chengxuya <1214237646@qq.com> Date: Mon, 31 Oct 2022 18:15:41 +0800 Subject: [PATCH 1/3] net_throw_error Signed-off-by: chengxuya <1214237646@qq.com> Change-Id: Ibf25a8d380d518e5fb3afb5bf8ab3c9a5cb4bd2e --- api/@ohos.net.connection.d.ts | 12 ++++++++++++ api/@ohos.net.socket.d.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/api/@ohos.net.connection.d.ts b/api/@ohos.net.connection.d.ts index 84576eeee7..261a8297d9 100644 --- a/api/@ohos.net.connection.d.ts +++ b/api/@ohos.net.connection.d.ts @@ -88,10 +88,22 @@ declare namespace connection { function getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback): void; function getNetCapabilities(netHandle: NetHandle): Promise; + /** + * Checks whether data traffic usage on the current network is metered. + * + * @param callback Returns {@code true} if data traffic usage on the current network is metered; + * returns {@code false} otherwise. + * @permission ohos.permission.GET_NETWORK_INFO + * @throws {BusinessError} 401 - Parameter error. + */ + function isDefaultNetMetered(callback: AsyncCallback): void; + function isDefaultNetMetered(): Promise; + /** * Checks whether the default data network is activated. * * @param callback Returns {@code true} if the default data network is activated; returns {@code false} otherwise. + * @throws {BusinessError} 401 - Parameter error. */ function hasDefaultNet(callback: AsyncCallback): void; function hasDefaultNet(): Promise; diff --git a/api/@ohos.net.socket.d.ts b/api/@ohos.net.socket.d.ts index 3fcdd5c8f9..dac92b91da 100644 --- a/api/@ohos.net.socket.d.ts +++ b/api/@ohos.net.socket.d.ts @@ -251,6 +251,7 @@ declare namespace socket { * * @param address Destination address. {@link NetAddress} * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ bind(address: NetAddress, callback: AsyncCallback): void; bind(address: NetAddress): Promise; @@ -276,6 +277,7 @@ declare namespace socket { /** * Closes a TCPSocket connection. * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ close(callback: AsyncCallback): void; close(): Promise; @@ -285,6 +287,7 @@ declare namespace socket { * * @param callback Callback used to return the result. {@link NetAddress} * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ getRemoteAddress(callback: AsyncCallback): void; getRemoteAddress(): Promise; @@ -294,6 +297,7 @@ declare namespace socket { * * @param callback Callback used to return the result. {@link SocketStateBase} * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ getState(callback: AsyncCallback): void; getState(): Promise; @@ -303,37 +307,50 @@ declare namespace socket { * * @param options Optional parameters {@link TCPExtraOptions}. * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback): void; setExtraOptions(options: TCPExtraOptions): Promise; /** * Listens for message receiving events of the TCPSocket connection. + * + * @throws {BusinessError} 401 - Parameter error. */ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void; /** * Cancels listening for message receiving events of the TCPSocket connection. + * + * @throws {BusinessError} 401 - Parameter error. */ off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void; /** * Listens for connection or close events of the TCPSocket connection. + * + * @throws {BusinessError} 401 - Parameter error. */ on(type: 'connect' | 'close', callback: Callback): void; /** * Cancels listening for connection or close events of the TCPSocket connection. + * + * @throws {BusinessError} 401 - Parameter error. */ off(type: 'connect' | 'close', callback?: Callback): void; /** * Listens for error events of the TCPSocket connection. + * + * @throws {BusinessError} 401 - Parameter error. */ on(type: 'error', callback: ErrorCallback): void; /** * Cancels listening for error events of the TCPSocket connection. + * + * @throws {BusinessError} 401 - Parameter error. */ off(type: 'error', callback?: ErrorCallback): void; } @@ -345,6 +362,8 @@ declare namespace socket { /** * Returns an object representing a local certificate. + * + * @throws {BusinessError} 401 - Parameter error. */ getCertificate(callback: AsyncCallback): void; getCertificate(): Promise; @@ -354,6 +373,8 @@ declare namespace socket { * an empty object will be returned. If the socket is destroyed, null is returned. * If needChain is true, it contains the complete certificate chain. Otherwise, * it only contains the peer's certificate. + * + * @throws {BusinessError} 401 - Parameter error. */ getRemoteCertificate(callback: AsyncCallback): void; getRemoteCertificate(): Promise; @@ -362,6 +383,8 @@ declare namespace socket { * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. * Server sockets or disconnected client sockets will return a value of null. + * + * @throws {BusinessError} 401 - Parameter error. */ getProtocol(callback: AsyncCallback): void; getProtocol(): Promise; @@ -369,6 +392,8 @@ declare namespace socket { /** * Returns an object containing the negotiated cipher suite information. * For example:{"name": "AES128-SHA256", "standardName": "TLS_RSA_WITH_AES_128_CBC_SHA256", "version": "TLSv1.2"} + * + * @throws {BusinessError} 401 - Parameter error. */ getCipherSuite(callback: AsyncCallback>): void; getCipherSuite(): Promise>; @@ -376,12 +401,15 @@ declare namespace socket { /** * The list of signature algorithms shared between the server and the client, in descending order of priority. * @see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html + * + * @throws {BusinessError} 401 - Parameter error. */ getSignatureAlgorithms(callback: AsyncCallback>): void; getSignatureAlgorithms(): Promise>; /** * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ connect(options: TLSConnectOptions, callback: AsyncCallback): void; connect(options: TLSConnectOptions): Promise; @@ -391,6 +419,7 @@ declare namespace socket { * * @param data Optional parameters {@link string}. * @permission ohos.permission.INTERNET + * @throws {BusinessError} 401 - Parameter error. */ send(data: string, callback: AsyncCallback): void; send(data: string): Promise; -- Gitee From d1c6f2ff238c3e15567dc42fd464da5c94005175 Mon Sep 17 00:00:00 2001 From: chengxuya <1214237646@qq.com> Date: Mon, 31 Oct 2022 21:11:52 +0800 Subject: [PATCH 2/3] add error code Signed-off-by: chengxuya <1214237646@qq.com> Change-Id: I98055d00a380f12cb487f0785fbb2cd147c3568a --- api/@ohos.net.connection.d.ts | 4 ++++ api/@ohos.net.socket.d.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/api/@ohos.net.connection.d.ts b/api/@ohos.net.connection.d.ts index 261a8297d9..58e6eecfcc 100644 --- a/api/@ohos.net.connection.d.ts +++ b/api/@ohos.net.connection.d.ts @@ -95,6 +95,8 @@ declare namespace connection { * returns {@code false} otherwise. * @permission ohos.permission.GET_NETWORK_INFO * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2100000 - NETMANAGER_SUCCESS. + * @throws {BusinessError} 2100201 - NETMANAGER_ERR_PERMISSION_DENIED. */ function isDefaultNetMetered(callback: AsyncCallback): void; function isDefaultNetMetered(): Promise; @@ -104,6 +106,8 @@ declare namespace connection { * * @param callback Returns {@code true} if the default data network is activated; returns {@code false} otherwise. * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2100000 - NETMANAGER_SUCCESS. + * @throws {BusinessError} 2100201 - NETMANAGER_ERR_PERMISSION_DENIED. */ function hasDefaultNet(callback: AsyncCallback): void; function hasDefaultNet(): Promise; diff --git a/api/@ohos.net.socket.d.ts b/api/@ohos.net.socket.d.ts index dac92b91da..6a0a53f0fd 100644 --- a/api/@ohos.net.socket.d.ts +++ b/api/@ohos.net.socket.d.ts @@ -252,6 +252,9 @@ declare namespace socket { * @param address Destination address. {@link NetAddress} * @permission ohos.permission.INTERNET * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303109 - TLS_ERR_SYS_EBADF. + * @throws {BusinessError} 2303113 - TLS_ERR_SYS_EACCES. + * @throws {BusinessError} 2303198 - TLS_ERR_SYS_EADDRINUSE. */ bind(address: NetAddress, callback: AsyncCallback): void; bind(address: NetAddress): Promise; @@ -278,6 +281,8 @@ declare namespace socket { * Closes a TCPSocket connection. * @permission ohos.permission.INTERNET * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303505 - TLS_ERR_SYSCALL. + * @throws {BusinessError} 2303506 - TLS_ERR_ZERO_RETURN. */ close(callback: AsyncCallback): void; close(): Promise; @@ -288,6 +293,9 @@ declare namespace socket { * @param callback Callback used to return the result. {@link NetAddress} * @permission ohos.permission.INTERNET * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303114 - TLS_ERR_SYS_EFAULT. + * @throws {BusinessError} 2303122 - TLS_ERR_SYS_EINVAL. + * @throws {BusinessError} 2303188 - TLS_ERR_SYS_ENOTSOCK. */ getRemoteAddress(callback: AsyncCallback): void; getRemoteAddress(): Promise; @@ -298,6 +306,9 @@ declare namespace socket { * @param callback Callback used to return the result. {@link SocketStateBase} * @permission ohos.permission.INTERNET * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303114 - TLS_ERR_SYS_EFAULT. + * @throws {BusinessError} 2303122 - TLS_ERR_SYS_EINVAL. + * @throws {BusinessError} 2303188 - TLS_ERR_SYS_ENOTSOCK. */ getState(callback: AsyncCallback): void; getState(): Promise; @@ -394,6 +405,9 @@ declare namespace socket { * For example:{"name": "AES128-SHA256", "standardName": "TLS_RSA_WITH_AES_128_CBC_SHA256", "version": "TLSv1.2"} * * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303502 - TLS_ERR_WANT_READ. + * @throws {BusinessError} 2303505 - TLS_ERR_SYSCALL. + * @throws {BusinessError} 2303506 - TLS_ERR_ZERO_RETURN. */ getCipherSuite(callback: AsyncCallback>): void; getCipherSuite(): Promise>; @@ -410,6 +424,18 @@ declare namespace socket { /** * @permission ohos.permission.INTERNET * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303104 - TLS_ERR_SYS_EINTR. + * @throws {BusinessError} 2303109 - TLS_ERR_SYS_EBADF. + * @throws {BusinessError} 2303111 - TLS_ERR_SYS_EAGAIN. + * @throws {BusinessError} 2303113 - TLS_ERR_SYS_EACCES. + * @throws {BusinessError} 2303188 - TLS_ERR_SYS_ENOTSOCK. + * @throws {BusinessError} 2303191 - TLS_ERR_SYS_EPROTOTYPE. + * @throws {BusinessError} 2303198 - TLS_ERR_SYS_EADDRINUSE. + * @throws {BusinessError} 2303199 - TLS_ERR_SYS_EADDRNOTAVAIL. + * @throws {BusinessError} 2303210 - TLS_ERR_SYS_ETIMEDOUT. + * @throws {BusinessError} 2303502 - TLS_ERR_WANT_READ. + * @throws {BusinessError} 2303505 - TLS_ERR_SYSCALL. + * @throws {BusinessError} 2303506 - TLS_ERR_ZERO_RETURN. */ connect(options: TLSConnectOptions, callback: AsyncCallback): void; connect(options: TLSConnectOptions): Promise; @@ -420,6 +446,9 @@ declare namespace socket { * @param data Optional parameters {@link string}. * @permission ohos.permission.INTERNET * @throws {BusinessError} 401 - Parameter error. + * @throws {BusinessError} 2303503 - TLS_ERR_WANT_WRITE. + * @throws {BusinessError} 2303505 - TLS_ERR_SYSCALL. + * @throws {BusinessError} 2303506 - TLS_ERR_ZERO_RETURN. */ send(data: string, callback: AsyncCallback): void; send(data: string): Promise; -- Gitee From b4c5d80b0f684b254672a9c0d26f2c4eb8e4010f Mon Sep 17 00:00:00 2001 From: chengxuya <1214237646@qq.com> Date: Mon, 31 Oct 2022 21:12:57 +0800 Subject: [PATCH 3/3] fix review Signed-off-by: chengxuya <1214237646@qq.com> Change-Id: I9911aec465bcd72a26d597f35c7eb58e7efad7aa --- api/@ohos.net.connection.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/@ohos.net.connection.d.ts b/api/@ohos.net.connection.d.ts index 58e6eecfcc..253a7574fd 100644 --- a/api/@ohos.net.connection.d.ts +++ b/api/@ohos.net.connection.d.ts @@ -88,7 +88,7 @@ declare namespace connection { function getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback): void; function getNetCapabilities(netHandle: NetHandle): Promise; - /** + /** * Checks whether data traffic usage on the current network is metered. * * @param callback Returns {@code true} if data traffic usage on the current network is metered; -- Gitee