@@ -41,7 +41,7 @@ type Host = {
41
41
| "hostUrl"
42
42
| "expectBinary"
43
43
| "isBinary"
44
- > ,
44
+ >
45
45
) => Promise < globalThis . Response & { request : globalThis . Request } > ;
46
46
/**
47
47
* @internal
@@ -134,8 +134,8 @@ function createHost(arangojsHostUrl: string, agentOptions?: any): Host {
134
134
headers . set (
135
135
"authorization" ,
136
136
`Basic ${ btoa (
137
- `${ baseUrl . username || "root" } :${ baseUrl . password || "" } ` ,
138
- ) } `,
137
+ `${ baseUrl . username || "root" } :${ baseUrl . password || "" } `
138
+ ) } `
139
139
) ;
140
140
}
141
141
const abortController = new AbortController ( ) ;
@@ -171,10 +171,15 @@ function createHost(arangojsHostUrl: string, agentOptions?: any): Host {
171
171
request,
172
172
arangojsHostUrl,
173
173
} ) ;
174
+ if ( fetchOptions ?. redirect === "manual" && isRedirect ( response ) ) {
175
+ throw new errors . HttpError ( response ) ;
176
+ }
174
177
} catch ( e : unknown ) {
175
178
const cause = e instanceof Error ? e : new Error ( String ( e ) ) ;
176
179
let error : errors . NetworkError ;
177
- if ( signal . aborted ) {
180
+ if ( cause instanceof errors . NetworkError ) {
181
+ error = cause ;
182
+ } else if ( signal . aborted ) {
178
183
const reason =
179
184
typeof signal . reason == "string" ? signal . reason : undefined ;
180
185
if ( reason === REASON_TIMEOUT ) {
@@ -276,7 +281,7 @@ const STATUS_CODE_DEFAULT_MESSAGES = {
276
281
277
282
type KnownStatusCode = keyof typeof STATUS_CODE_DEFAULT_MESSAGES ;
278
283
const KNOWN_STATUS_CODES = Object . keys ( STATUS_CODE_DEFAULT_MESSAGES ) . map ( ( k ) =>
279
- Number ( k ) ,
284
+ Number ( k )
280
285
) as KnownStatusCode [ ] ;
281
286
const REDIRECT_CODES = [ 301 , 302 , 303 , 307 , 308 ] satisfies KnownStatusCode [ ] ;
282
287
type RedirectStatusCode = ( typeof REDIRECT_CODES ) [ number ] ;
@@ -292,9 +297,11 @@ function isKnownStatusCode(code: number): code is KnownStatusCode {
292
297
}
293
298
294
299
/**
300
+ * @internal
301
+ *
295
302
* Indicates whether the given status code represents a redirect.
296
303
*/
297
- export function isRedirect ( response : ProcessedResponse ) : boolean {
304
+ function isRedirect ( response : ProcessedResponse ) : boolean {
298
305
return REDIRECT_CODES . includes ( response . status as RedirectStatusCode ) ;
299
306
}
300
307
@@ -333,7 +340,7 @@ export type ArangoApiResponse<T> = T & ArangoResponseMetadata;
333
340
* Indicates whether the given value represents an ArangoDB error response.
334
341
*/
335
342
export function isArangoErrorResponse (
336
- body : unknown ,
343
+ body : unknown
337
344
) : body is ArangoErrorResponse {
338
345
if ( ! body || typeof body !== "object" ) return false ;
339
346
const obj = body as Record < string , unknown > ;
@@ -576,7 +583,7 @@ export type CommonRequestOptions = {
576
583
*/
577
584
afterResponse ?: (
578
585
err : errors . NetworkError | null ,
579
- res ?: globalThis . Response & { request : globalThis . Request } ,
586
+ res ?: globalThis . Response & { request : globalThis . Request }
580
587
) => void | Promise < void > ;
581
588
} ;
582
589
@@ -726,11 +733,11 @@ export class Connection {
726
733
727
734
this . _commonFetchOptions . headers . set (
728
735
"x-arango-version" ,
729
- String ( arangoVersion ) ,
736
+ String ( arangoVersion )
730
737
) ;
731
738
this . _commonFetchOptions . headers . set (
732
739
"x-arango-driver" ,
733
- `arangojs/${ process . env . ARANGOJS_VERSION } (cloud)` ,
740
+ `arangojs/${ process . env . ARANGOJS_VERSION } (cloud)`
734
741
) ;
735
742
736
743
this . addToHostList ( URLS ) ;
@@ -908,7 +915,7 @@ export class Connection {
908
915
setBasicAuth ( auth : configuration . BasicAuthCredentials ) {
909
916
this . setHeader (
910
917
"authorization" ,
911
- `Basic ${ btoa ( `${ auth . username } :${ auth . password } ` ) } ` ,
918
+ `Basic ${ btoa ( `${ auth . username } :${ auth . password } ` ) } `
912
919
) ;
913
920
}
914
921
@@ -942,7 +949,7 @@ export class Connection {
942
949
*/
943
950
database (
944
951
databaseName : string ,
945
- database : databases . Database ,
952
+ database : databases . Database
946
953
) : databases . Database ;
947
954
/**
948
955
* @internal
@@ -956,7 +963,7 @@ export class Connection {
956
963
database ( databaseName : string , database : null ) : undefined ;
957
964
database (
958
965
databaseName : string ,
959
- database ?: databases . Database | null ,
966
+ database ?: databases . Database | null
960
967
) : databases . Database | undefined {
961
968
if ( database === null ) {
962
969
this . _databases . delete ( databaseName ) ;
@@ -987,7 +994,7 @@ export class Connection {
987
994
const i = this . _hostUrls . indexOf ( url ) ;
988
995
if ( i !== - 1 ) return this . _hosts [ i ] ;
989
996
return createHost ( url ) ;
990
- } ) ,
997
+ } )
991
998
) ;
992
999
this . _hostUrls . splice ( 0 , this . _hostUrls . length , ...cleanUrls ) ;
993
1000
}
@@ -1003,10 +1010,10 @@ export class Connection {
1003
1010
*/
1004
1011
addToHostList ( urls : string | string [ ] ) : string [ ] {
1005
1012
const cleanUrls = ( Array . isArray ( urls ) ? urls : [ urls ] ) . map ( ( url ) =>
1006
- util . normalizeUrl ( url ) ,
1013
+ util . normalizeUrl ( url )
1007
1014
) ;
1008
1015
const newUrls = cleanUrls . filter (
1009
- ( url ) => this . _hostUrls . indexOf ( url ) === - 1 ,
1016
+ ( url ) => this . _hostUrls . indexOf ( url ) === - 1
1010
1017
) ;
1011
1018
this . _hostUrls . push ( ...newUrls ) ;
1012
1019
this . _hosts . push ( ...newUrls . map ( ( url ) => createHost ( url ) ) ) ;
@@ -1127,8 +1134,8 @@ export class Connection {
1127
1134
res : globalThis . Response & {
1128
1135
request : globalThis . Request ;
1129
1136
parsedBody ?: any ;
1130
- } ,
1131
- ) => T ,
1137
+ }
1138
+ ) => T
1132
1139
) : Promise < T > {
1133
1140
const {
1134
1141
hostUrl,
@@ -1146,7 +1153,7 @@ export class Connection {
1146
1153
1147
1154
const headers = util . mergeHeaders (
1148
1155
this . _commonFetchOptions . headers ,
1149
- requestHeaders ,
1156
+ requestHeaders
1150
1157
) ;
1151
1158
1152
1159
let body = requestBody ;
0 commit comments