@@ -46,8 +46,8 @@ export function createRequest(
4646 else agent = new HttpAgent ( agentOptions ) ;
4747 }
4848 return function request (
49- { method, url, headers, body, expectBinary = false } : RequestOptions ,
50- cb : Errback < ArangojsResponse >
49+ { method, url, headers, body } : RequestOptions ,
50+ callback : Errback < ArangojsResponse >
5151 ) {
5252 let path = baseUrlParts . pathname
5353 ? url . pathname
@@ -64,10 +64,7 @@ export function createRequest(
6464 options . hostname = baseUrlParts . hostname ;
6565 options . port = baseUrlParts . port ;
6666 options . auth = baseUrlParts . auth ;
67- let callback : Errback < IncomingMessage > = ( err , res ) => {
68- callback = ( ) => undefined ;
69- cb ( err , res ) ;
70- } ;
67+ let called = false ;
7168 const req = ( isTls ? httpsRequest : httpRequest ) (
7269 options ,
7370 ( res : IncomingMessage ) => {
@@ -76,17 +73,18 @@ export function createRequest(
7673 res . on ( "end" , ( ) => {
7774 const result = res as ArangojsResponse ;
7875 result . body = Buffer . concat ( data ) ;
79- if ( ! expectBinary ) {
80- result . body = result . body . toString ( "utf-8" ) ;
81- }
76+ if ( called ) return ;
77+ called = true ;
8278 callback ( null , result ) ;
8379 } ) ;
8480 }
8581 ) ;
8682 req . on ( "error" , err => {
8783 const error = err as ArangojsError ;
8884 error . request = req ;
89- callback ( error ) ;
85+ if ( called ) return ;
86+ called = true ;
87+ callback ( err ) ;
9088 } ) ;
9189 if ( body ) req . write ( body ) ;
9290 req . end ( ) ;
0 commit comments