diff --git a/index.js b/index.js index 0a29dbf..e8dc3cd 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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 diff --git a/test/index.test.js b/test/index.test.js index 487c1a6..c741de9 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -259,6 +259,7 @@ describe('index', function() { }, error => { assert.match(error.message, expectedError); + assert.match(error.statusCode, 400); } ); });