Skip to content

Commit 1f20dee

Browse files
improve auth error
1 parent 60dde2b commit 1f20dee

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/cli.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ const espressoCommand = program
179179
});
180180
if (credentials === null) {
181181
throw new Error(
182-
'Please specify credentials via --api-key/--api-secret, TB_KEY/TB_SECRET environment variables, or ~/.testingbot file',
182+
'No TestingBot credentials found. Please authenticate using one of these methods:\n' +
183+
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
184+
' 2. Use --api-key and --api-secret options\n' +
185+
' 3. Set TB_KEY and TB_SECRET environment variables\n' +
186+
' 4. Create ~/.testingbot file with content: key:secret',
183187
);
184188
}
185189
const espresso = new Espresso(credentials, options);
@@ -365,7 +369,11 @@ const maestroCommand = program
365369
});
366370
if (credentials === null) {
367371
throw new Error(
368-
'Please specify credentials via --api-key/--api-secret, TB_KEY/TB_SECRET environment variables, or ~/.testingbot file',
372+
'No TestingBot credentials found. Please authenticate using one of these methods:\n' +
373+
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
374+
' 2. Use --api-key and --api-secret options\n' +
375+
' 3. Set TB_KEY and TB_SECRET environment variables\n' +
376+
' 4. Create ~/.testingbot file with content: key:secret',
369377
);
370378
}
371379
const maestro = new Maestro(credentials, options);
@@ -482,7 +490,11 @@ const xcuitestCommand = program
482490
});
483491
if (credentials === null) {
484492
throw new Error(
485-
'Please specify credentials via --api-key/--api-secret, TB_KEY/TB_SECRET environment variables, or ~/.testingbot file',
493+
'No TestingBot credentials found. Please authenticate using one of these methods:\n' +
494+
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
495+
' 2. Use --api-key and --api-secret options\n' +
496+
' 3. Set TB_KEY and TB_SECRET environment variables\n' +
497+
' 4. Create ~/.testingbot file with content: key:secret',
486498
);
487499
}
488500
const xcuitest = new XCUITest(credentials, options);

src/upload.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export default class Upload {
8080
throw error;
8181
}
8282
if (axios.isAxiosError(error)) {
83+
if (error.response?.status === 401) {
84+
throw new TestingBotError(
85+
'Invalid TestingBot credentials. Please check your API key and secret.\n' +
86+
'You can update your credentials by running "testingbot login" or by using:\n' +
87+
' --api-key and --api-secret options\n' +
88+
' TB_KEY and TB_SECRET environment variables\n' +
89+
' ~/.testingbot file with content: key:secret',
90+
);
91+
}
8392
const message = error.response?.data?.error || error.message;
8493
throw new TestingBotError(`Upload failed: ${message}`);
8594
}

tests/cli.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ describe('TestingBotCTL CLI', () => {
306306
]);
307307

308308
expect(mockError).toHaveBeenCalledWith(
309-
'Espresso error: Please specify credentials via --api-key/--api-secret, TB_KEY/TB_SECRET environment variables, or ~/.testingbot file',
309+
'Espresso error: No TestingBot credentials found. Please authenticate using one of these methods:\n' +
310+
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
311+
' 2. Use --api-key and --api-secret options\n' +
312+
' 3. Set TB_KEY and TB_SECRET environment variables\n' +
313+
' 4. Create ~/.testingbot file with content: key:secret',
310314
);
311315
});
312316

@@ -327,7 +331,11 @@ describe('TestingBotCTL CLI', () => {
327331
]);
328332

329333
expect(mockError).toHaveBeenCalledWith(
330-
'Maestro error: Please specify credentials via --api-key/--api-secret, TB_KEY/TB_SECRET environment variables, or ~/.testingbot file',
334+
'Maestro error: No TestingBot credentials found. Please authenticate using one of these methods:\n' +
335+
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
336+
' 2. Use --api-key and --api-secret options\n' +
337+
' 3. Set TB_KEY and TB_SECRET environment variables\n' +
338+
' 4. Create ~/.testingbot file with content: key:secret',
331339
);
332340
});
333341

@@ -350,7 +358,11 @@ describe('TestingBotCTL CLI', () => {
350358
]);
351359

352360
expect(mockError).toHaveBeenCalledWith(
353-
'XCUITest error: Please specify credentials via --api-key/--api-secret, TB_KEY/TB_SECRET environment variables, or ~/.testingbot file',
361+
'XCUITest error: No TestingBot credentials found. Please authenticate using one of these methods:\n' +
362+
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
363+
' 2. Use --api-key and --api-secret options\n' +
364+
' 3. Set TB_KEY and TB_SECRET environment variables\n' +
365+
' 4. Create ~/.testingbot file with content: key:secret',
354366
);
355367
});
356368

0 commit comments

Comments
 (0)