Skip to content

Commit

Permalink
fix: Porting throwError function for proper error handling of parseUrl (
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshwata authored Mar 7, 2022
1 parent 84007ae commit ea40032
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ const DESCRIPTION_MAP = {
PENDING: 'Parked it as Pending...'
};

/**
* Throw error with error code
* @param {String} errorReason Error message
* @param {Number} errorCode Error code
* @throws {Error} Throws error
*/
function throwError(errorReason, errorCode = 500) {
const err = new Error(errorReason);

err.statusCode = errorCode;
throw err;
}

/**
* Get repo information
* @method getRepoInfoByCheckoutUrl
Expand Down Expand Up @@ -336,7 +349,7 @@ class GitlabScm extends Scm {
if (hostname !== myHost) {
const message = 'This checkoutUrl is not supported for your current login host.';

throw new Error(message);
throwError(message, 400);
}

return this.breaker
Expand Down
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe('index', function() {
},
error => {
assert.match(error.message, expectedError);
assert.match(error.statusCode, 400);
}
);
});
Expand Down

0 comments on commit ea40032

Please sign in to comment.