Skip to content

Commit 9d69b0b

Browse files
committed
Improve error handling
1 parent d12693e commit 9d69b0b

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

index.js

+14
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ module.exports = {
8888
} else {
8989
this.log('uploaded to chrome web store succesfully', { verbose: true });
9090
}
91+
})
92+
.catch((error) => {
93+
if (error.response) {
94+
error = `uploading to chrome web store failed: ${error.response.body.error}`;
95+
}
96+
97+
return Promise.reject(error);
9198
});
9299
} else {
93100
return Promise.resolve();
@@ -108,6 +115,13 @@ module.exports = {
108115
.then(this._publishToChromeWebStore.bind(this, publishTarget))
109116
.then(() => {
110117
this.log('published to chrome web store succesfully', { verbose: true });
118+
})
119+
.catch((error) => {
120+
if (error.response) {
121+
error = `publishing to chrome web store failed: ${error.response.body.error}`;
122+
}
123+
124+
return Promise.reject(error);
111125
});
112126
} else {
113127
return Promise.resolve();

node-tests/index-test.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,21 @@ describe('ember-cli-deploy-chrome-app plugin', function() {
283283
return rimraf(distDir);
284284
});
285285

286-
describe('when the request fails', function() {
286+
describe('when the oauth token request fails', function() {
287+
beforeEach(function() {
288+
nock('https://www.googleapis.com')
289+
.post('/oauth2/v4/token')
290+
.reply(400, {
291+
error: 'invalid grant'
292+
});
293+
});
294+
295+
it('fails to upload the zip file to the chrome webstore', function() {
296+
return expect(plugin.upload(context)).to.be.rejected;
297+
});
298+
});
299+
300+
describe('when the upload request fails', function() {
287301
beforeEach(function() {
288302
nock('https://www.googleapis.com')
289303
.post('/oauth2/v4/token')
@@ -301,7 +315,7 @@ describe('ember-cli-deploy-chrome-app plugin', function() {
301315
});
302316
});
303317

304-
describe('when the request succeeds', function() {
318+
describe('when the upload request succeeds', function() {
305319
beforeEach(function() {
306320
nock('https://www.googleapis.com')
307321
.post('/oauth2/v4/token')
@@ -362,19 +376,21 @@ describe('ember-cli-deploy-chrome-app plugin', function() {
362376
plugin.configure(context);
363377
});
364378

365-
describe('when the request fails', function() {
379+
describe('when the oauth token request fails', function() {
366380
beforeEach(function() {
367381
nock('https://www.googleapis.com')
368382
.post('/oauth2/v4/token')
369-
.reply(401);
383+
.reply(401, {
384+
error: 'invalid_grant'
385+
});
370386
});
371387

372388
it('fails to publish to the chrome webstore', function() {
373389
return expect(plugin.activate(context)).to.be.rejected;
374390
});
375391
});
376392

377-
describe('when the request succeeds', function() {
393+
describe('when the publish request succeeds', function() {
378394
beforeEach(function() {
379395
nock('https://www.googleapis.com')
380396
.post('/oauth2/v4/token')

0 commit comments

Comments
 (0)