Skip to content

Commit

Permalink
[Refactor] prefer second .then arg over .catch
Browse files Browse the repository at this point in the history
Since `.then` is always present, but `.catch` isn’t
  • Loading branch information
ljharb committed Sep 21, 2023
1 parent 5ba89c9 commit 135a952
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/test.js
Expand Up @@ -116,18 +116,21 @@ Test.prototype.run = function run() {
&& typeof callbackReturn.then === 'function'
) {
var self = this;
Promise.resolve(callbackReturn).then(function onResolve() {
if (!self.calledEnd) {
Promise.resolve(callbackReturn).then(
function onResolve() {
if (!self.calledEnd) {
self.end();
}
},
function onError(err) {
if (err instanceof Error || objectToString(err) === '[object Error]') {
self.ifError(err);
} else {
self.fail(err);
}
self.end();
}
})['catch'](function onError(err) {
if (err instanceof Error || objectToString(err) === '[object Error]') {
self.ifError(err);
} else {
self.fail(err);
}
self.end();
});
);
return;
}

Expand Down

0 comments on commit 135a952

Please sign in to comment.