Fix lint errors for promise-reject-errors

Change-Id: I7d21e3bfaa81a21e5a5fc864ca09db17dc92abd8
This commit is contained in:
Thomas Shafer
2019-02-07 14:40:02 -08:00
parent 520d92157a
commit 2a1a93b687
10 changed files with 24 additions and 19 deletions

View File

@@ -63,7 +63,6 @@
"object-shorthand": ["error", "always"], "object-shorthand": ["error", "always"],
"prefer-arrow-callback": "error", "prefer-arrow-callback": "error",
"prefer-const": "error", "prefer-const": "error",
"prefer-promise-reject-errors": "off",
"prefer-spread": "error", "prefer-spread": "error",
"quote-props": ["error", "consistent-as-needed"], "quote-props": ["error", "consistent-as-needed"],
"require-jsdoc": "off", "require-jsdoc": "off",

View File

@@ -232,7 +232,8 @@ limitations under the License.
return restAPI.getChangeDetail(change._number) return restAPI.getChangeDetail(change._number)
.then(detail => { .then(detail => {
if (!detail) { if (!detail) {
return Promise.reject('Unable to check for latest patchset.'); const error = new Error('Unable to check for latest patchset.');
return Promise.reject(error);
} }
const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum( const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum(
Gerrit.PatchSetBehavior.computeAllPatchSets(detail)); Gerrit.PatchSetBehavior.computeAllPatchSets(detail));

View File

@@ -233,9 +233,10 @@ limitations under the License.
const memberName = 'bad-name'; const memberName = 'bad-name';
const alertStub = sandbox.stub(); const alertStub = sandbox.stub();
element.addEventListener('show-alert', alertStub); element.addEventListener('show-alert', alertStub);
const error = new Error('error');
error.status = 404;
sandbox.stub(element.$.restAPI, 'saveGroupMembers', sandbox.stub(element.$.restAPI, 'saveGroupMembers',
() => Promise.reject({status: 404})); () => Promise.reject(error));
element.$.groupMemberSearchInput.text = memberName; element.$.groupMemberSearchInput.text = memberName;
element.$.groupMemberSearchInput.value = 1234; element.$.groupMemberSearchInput.value = 1234;

View File

@@ -64,7 +64,9 @@ limitations under the License.
}); });
}, },
send(method, url, payload) { send(method, url, payload) {
if (method !== 'POST') { return Promise.reject('bad method'); } if (method !== 'POST') {
return Promise.reject(new Error('bad method'));
}
if (url === '/changes/test~42/revisions/2/submit') { if (url === '/changes/test~42/revisions/2/submit') {
return Promise.resolve({ return Promise.resolve({
@@ -78,7 +80,7 @@ limitations under the License.
}); });
} }
return Promise.reject('bad url'); return Promise.reject(new Error('bad url'));
}, },
getProjectConfig() { return Promise.resolve({}); }, getProjectConfig() { return Promise.resolve({}); },
}); });

View File

@@ -622,7 +622,7 @@
return Promise.resolve(); return Promise.resolve();
} else { } else {
this._redirectToLogin(data.canonicalPath); this._redirectToLogin(data.canonicalPath);
return Promise.reject(); return Promise.reject(new Error());
} }
}); });
}, },

View File

@@ -169,7 +169,7 @@ limitations under the License.
const newKeyString = 'not even close to valid'; const newKeyString = 'not even close to valid';
const addStub = sinon.stub(element.$.restAPI, 'addAccountGPGKey', const addStub = sinon.stub(element.$.restAPI, 'addAccountGPGKey',
() => { return Promise.reject(); }); () => { return Promise.reject(new Error('error')); });
element._newKey = newKeyString; element._newKey = newKeyString;

View File

@@ -155,7 +155,7 @@ limitations under the License.
const newKeyString = 'not even close to valid'; const newKeyString = 'not even close to valid';
const addStub = sinon.stub(element.$.restAPI, 'addAccountSSHKey', const addStub = sinon.stub(element.$.restAPI, 'addAccountSSHKey',
() => { return Promise.reject(); }); () => { return Promise.reject(new Error('error')); });
element._newKey = newKeyString; element._newKey = newKeyString;

View File

@@ -135,7 +135,7 @@ limitations under the License.
__key: 'key', __key: 'key',
__url: '/changes/1/revisions/2/foo~bar', __url: '/changes/1/revisions/2/foo~bar',
}; };
const sendStub = sandbox.stub().returns(Promise.reject('boom')); const sendStub = sandbox.stub().returns(Promise.reject(new Error('boom')));
sandbox.stub(plugin, 'restApi').returns({ sandbox.stub(plugin, 'restApi').returns({
send: sendStub, send: sendStub,
}); });

View File

@@ -2506,7 +2506,9 @@
_fetchB64File(url) { _fetchB64File(url) {
return this._fetch({url: this.getBaseUrl() + url}) return this._fetch({url: this.getBaseUrl() + url})
.then(response => { .then(response => {
if (!response.ok) { return Promise.reject(response.statusText); } if (!response.ok) {
return Promise.reject(new Error(response.statusText));
}
const type = response.headers.get('X-FYI-Content-Type'); const type = response.headers.get('X-FYI-Content-Type');
return response.text() return response.text()
.then(text => { .then(text => {
@@ -2666,12 +2668,12 @@
return this._send(req) return this._send(req)
.then(response => { .then(response => {
if (response.status < 200 && response.status >= 300) { if (response.status < 200 && response.status >= 300) {
return Promise.reject(); return Promise.reject(new Error('error'));
} }
return this.getResponseObject(response); return this.getResponseObject(response);
}) })
.then(obj => { .then(obj => {
if (!obj.valid) { return Promise.reject(); } if (!obj.valid) { return Promise.reject(new Error('error')); }
return obj; return obj;
}); });
}, },
@@ -2701,12 +2703,12 @@
return this._send(req) return this._send(req)
.then(response => { .then(response => {
if (response.status < 200 && response.status >= 300) { if (response.status < 200 && response.status >= 300) {
return Promise.reject(); return Promise.reject(new Error('error'));
} }
return this.getResponseObject(response); return this.getResponseObject(response);
}) })
.then(obj => { .then(obj => {
if (!obj) { return Promise.reject(); } if (!obj) { return Promise.reject(new Error('error')); }
return obj; return obj;
}); });
}, },

View File

@@ -88,10 +88,10 @@ limitations under the License.
}); });
test('cached promise', done => { test('cached promise', done => {
const promise = Promise.reject('foo'); const promise = Promise.reject(new Error('foo'));
element._cache.set('/foo', promise); element._cache.set('/foo', promise);
element._fetchSharedCacheURL({url: '/foo'}).catch(p => { element._fetchSharedCacheURL({url: '/foo'}).catch(p => {
assert.equal(p, 'foo'); assert.equal(p.message, 'foo');
done(); done();
}); });
}); });
@@ -455,7 +455,7 @@ limitations under the License.
status: 403, status: 403,
}; };
window.fetch.onFirstCall().returns( window.fetch.onFirstCall().returns(
Promise.reject({message: 'Failed to fetch'})); Promise.reject(new Error('Failed to fetch')));
window.fetch.onSecondCall().returns(Promise.resolve(fakeAuthResponse)); window.fetch.onSecondCall().returns(Promise.resolve(fakeAuthResponse));
// Emulate logged in. // Emulate logged in.
element._cache.set('/accounts/self/detail', {}); element._cache.set('/accounts/self/detail', {});
@@ -507,7 +507,7 @@ limitations under the License.
element._cache.set('/accounts/self/detail', true); element._cache.set('/accounts/self/detail', true);
sandbox.spy(element, 'checkCredentials'); sandbox.spy(element, 'checkCredentials');
sandbox.stub(window, 'fetch', url => { sandbox.stub(window, 'fetch', url => {
return Promise.reject({message: 'Failed to fetch'}); return Promise.reject(new Error('Failed to fetch'));
}); });
return element.getConfig(true) return element.getConfig(true)
.catch(err => undefined) .catch(err => undefined)