File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
packages/@n8n/benchmark/src/n8nApiClient Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 1
- import { strict as assert } from 'node:assert' ;
2
1
import type { AxiosRequestConfig } from 'axios' ;
3
2
import { N8nApiClient } from './n8nApiClient' ;
4
3
@@ -16,15 +15,33 @@ export class AuthenticatedN8nApiClient extends N8nApiClient {
16
15
email : string ;
17
16
password : string ;
18
17
} ,
19
- ) {
18
+ ) : Promise < AuthenticatedN8nApiClient > {
20
19
const response = await apiClient . restApiRequest ( '/login' , {
21
20
method : 'POST' ,
22
21
data : loginDetails ,
23
22
} ) ;
24
23
24
+ if ( response . data === 'n8n is starting up. Please wait' ) {
25
+ await apiClient . delay ( 1000 ) ;
26
+ return await this . createUsingUsernameAndPassword ( apiClient , loginDetails ) ;
27
+ }
28
+
25
29
const cookieHeader = response . headers [ 'set-cookie' ] ;
26
30
const authCookie = Array . isArray ( cookieHeader ) ? cookieHeader . join ( '; ' ) : cookieHeader ;
27
- assert ( authCookie ) ;
31
+ if ( ! authCookie ) {
32
+ throw new Error (
33
+ 'Did not receive authentication cookie even tho login succeeded: ' +
34
+ JSON . stringify (
35
+ {
36
+ status : response . status ,
37
+ headers : response . headers ,
38
+ data : response . data ,
39
+ } ,
40
+ null ,
41
+ 2 ,
42
+ ) ,
43
+ ) ;
44
+ }
28
45
29
46
return new AuthenticatedN8nApiClient ( apiClient . apiBaseUrl , authCookie ) ;
30
47
}
Original file line number Diff line number Diff line change @@ -75,11 +75,11 @@ export class N8nApiClient {
75
75
}
76
76
}
77
77
78
- protected getRestEndpointUrl ( endpoint : string ) {
79
- return ` ${ this . apiBaseUrl } /rest ${ endpoint } ` ;
78
+ async delay ( ms : number ) : Promise < void > {
79
+ return await new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
80
80
}
81
81
82
- private async delay ( ms : number ) : Promise < void > {
83
- return await new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
82
+ protected getRestEndpointUrl ( endpoint : string ) {
83
+ return ` ${ this . apiBaseUrl } /rest ${ endpoint } ` ;
84
84
}
85
85
}
You can’t perform that action at this time.
0 commit comments