1717const rclnodejs = require ( './native_loader.js' ) ;
1818const DistroUtils = require ( './distro.js' ) ;
1919const Entity = require ( './entity.js' ) ;
20- const {
21- TypeValidationError,
22- TimeoutError,
23- AbortError,
24- } = require ( './errors.js' ) ;
2520const debug = require ( 'debug' ) ( 'rclnodejs:client' ) ;
2621
2722// Polyfill for AbortSignal.any() for Node.js <= 20.3.0
@@ -101,10 +96,7 @@ class Client extends Entity {
10196 */
10297 sendRequest ( request , callback ) {
10398 if ( typeof callback !== 'function' ) {
104- throw new TypeValidationError ( 'callback' , callback , 'function' , {
105- entityType : 'service' ,
106- entityName : this . _serviceName ,
107- } ) ;
99+ throw new TypeError ( 'Invalid argument' ) ;
108100 }
109101
110102 let requestToSend =
@@ -125,8 +117,8 @@ class Client extends Entity {
125117 * @param {number } [options.timeout] - Timeout in milliseconds for the request.
126118 * @param {AbortSignal } [options.signal] - AbortSignal to cancel the request.
127119 * @return {Promise<object> } Promise that resolves with the service response.
128- * @throws {module:rclnodejs. TimeoutError } If the request times out (when options.timeout is exceeded).
129- * @throws {module:rclnodejs. AbortError } If the request is manually aborted (via options.signal).
120+ * @throws {TimeoutError } If the request times out (when options.timeout is exceeded).
121+ * @throws {AbortError } If the request is manually aborted (via options.signal).
130122 * @throws {Error } If the request fails for other reasons.
131123 */
132124 sendRequestAsync ( request , options = { } ) {
@@ -160,31 +152,31 @@ class Client extends Entity {
160152
161153 if ( effectiveSignal ) {
162154 if ( effectiveSignal . aborted ) {
163- const error = isTimeout
164- ? new TimeoutError ( 'Service request' , options . timeout , {
165- entityType : 'service' ,
166- entityName : this . _serviceName ,
167- } )
168- : new AbortError ( 'Service request' , undefined , {
169- entityType : 'service' ,
170- entityName : this . _serviceName ,
171- } ) ;
155+ const error = new Error (
156+ isTimeout
157+ ? `Request timeout after ${ options . timeout } ms`
158+ : 'Request was aborted'
159+ ) ;
160+ error . name = isTimeout ? 'TimeoutError' : 'AbortError' ;
161+ if ( isTimeout ) {
162+ error . code = 'TIMEOUT' ;
163+ }
172164 reject ( error ) ;
173165 return ;
174166 }
175167
176168 effectiveSignal . addEventListener ( 'abort' , ( ) => {
177169 if ( ! isResolved ) {
178170 cleanup ( ) ;
179- const error = isTimeout
180- ? new TimeoutError ( 'Service request' , options . timeout , {
181- entityType : 'service' ,
182- entityName : this . _serviceName ,
183- } )
184- : new AbortError ( 'Service request' , undefined , {
185- entityType : 'service' ,
186- entityName : this . _serviceName ,
187- } ) ;
171+ const error = new Error (
172+ isTimeout
173+ ? `Request timeout after ${ options . timeout } ms`
174+ : 'Request was aborted'
175+ ) ;
176+ error . name = isTimeout ? 'TimeoutError' : 'AbortError' ;
177+ if ( isTimeout ) {
178+ error . code = 'TIMEOUT' ;
179+ }
188180 reject ( error ) ;
189181 }
190182 } ) ;
0 commit comments