Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Porting throwError function for proper error handling of parseUrl #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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