Skip to content

Commit 91faa94

Browse files
AndreyBelymVasilyStrelyaev
authored andcommitted
Improve authentication error message (closes #1) (#3)
* Improve authentication error message (closes #1) * Fix message
1 parent 73bdfcc commit 91faa94

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "testcafe-browser-provider-browserstack",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "browserstack TestCafe browser provider plugin.",
55
"repository": "https://github.com/DevExpress/testcafe-browser-provider-browserstack",
66
"homepage": "https://github.com/DevExpress/testcafe-browser-provider-browserstack",

src/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const MINIMAL_WORKER_TIME = 30000;
1414
const TESTCAFE_CLOSING_TIMEOUT = 10000;
1515
const TOO_SMALL_TIME_FOR_WAITING = MINIMAL_WORKER_TIME - TESTCAFE_CLOSING_TIMEOUT;
1616

17+
const AUTH_FAILED_ERROR = 'Authentication failed. Please assign the correct username and access key ' +
18+
'to the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables.';
19+
1720
const BROWSERSTACK_API_PATHS = {
1821
browserList: {
1922
url: 'https://api.browserstack.com/4/browsers?flat=true'
@@ -74,6 +77,9 @@ function destroyBrowserStackConnector (connector) {
7477
}
7578

7679
function doRequest (apiPath, params) {
80+
if (!process.env['BROWSERSTACK_USERNAME'] || !process.env['BROWSERSTACK_ACCESS_KEY'])
81+
throw new Error(AUTH_FAILED_ERROR);
82+
7783
var url = apiPath.url;
7884

7985
if (params)
@@ -92,7 +98,13 @@ function doRequest (apiPath, params) {
9298
if (apiPath.binaryStream)
9399
opts.encoding = null;
94100

95-
return request(url, opts);
101+
return request(url, opts)
102+
.catch(error => {
103+
if (error.statusCode === 401)
104+
throw new Error(AUTH_FAILED_ERROR);
105+
106+
throw error;
107+
});
96108
}
97109

98110
export default {

0 commit comments

Comments
 (0)