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: [3] fix the error handling of getCommitSha #2362

Merged
merged 13 commits into from
Mar 10, 2021

Conversation

itleigns
Copy link
Contributor

@itleigns itleigns commented Mar 1, 2021

Context

If we run a job in a pipeline whose corresponding SCM branch has been deleted, 500 error is thrown.
It is appropriate to throw 404 error in this case so we want to change that way.

Objective

  • We change the error status the /event endpoint throws when we run a job in a pipeline whose corresponding SCM branch has been deleted. We set error status as 404.
  • We add a test for it.
  • We eliminated unnecessary variable assignments in test code for refactoring.

Context

We change the format of the error returned by getCommitSha in this PR so we change the error handling of getCommitSha accordingly.

Objective

  • We change the error handling of getCommitSha.
  • We change a test to follow this PR.
  • We add a test in case we run a pipeline with the corresponding SCM branch deleted.
  • We eliminated unnecessary variable assignments in test code for refactoring.

Reference

screwdriver-cd/scm-gitlab#36
screwdriver-cd/scm-bitbucket#75

License

I confirm that this contribution is made under a BSD license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@coveralls
Copy link

coveralls commented Mar 1, 2021

Coverage Status

Coverage decreased (-0.02%) to 95.738% when pulling 850b312 on sonic-screwdriver-cd:branch-not-found into ac25ac9 on screwdriver-cd:master.

test/plugins/events.test.js Outdated Show resolved Hide resolved
Copy link
Member

@tkyi tkyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion, otherwise LGTM

Copy link

@MysticDoll MysticDoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you read another scm component?
For example, getCommitSha in scm-gitlab checks response by checkResponseError. And this function set response.statusCode to error.code and also set response.body.message to error.message. Therefore the error object from scm-gitlab does not have status member and it is not guaranteed that error.message always has Branch not found in this case.

I think you should make the interfaces of errors in scm component common by using boom.notFound.

@itleigns itleigns changed the title fix: fix the error status /events endpoint throws fix: fix the error handling of getCommitSha Mar 3, 2021
@itleigns itleigns changed the title fix: fix the error handling of getCommitSha fix: [2] fix the error handling of getCommitSha Mar 3, 2021
@itleigns itleigns changed the title fix: [2] fix the error handling of getCommitSha fix: [3] fix the error handling of getCommitSha Mar 4, 2021
plugins/events/create.js Outdated Show resolved Hide resolved
Co-authored-by: Mitsuru Takigahira <[email protected]>
})
.catch(err => {
if (err.status === 404) {
throw boom.notFound(err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the following code, you may be able to handle errors other than 404 with boom.
throw boom.boomify(err, {statusCode: err.status})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx. I fixed it.

Copy link
Contributor

@kkokufud kkokufud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jithine jithine closed this Mar 9, 2021
@jithine jithine reopened this Mar 9, 2021
@tkyi tkyi merged commit c51c7db into screwdriver-cd:master Mar 10, 2021
@kkisic kkisic deleted the branch-not-found branch March 12, 2021 05:03
ibu1224 pushed a commit to sonic-screwdriver-cd/screwdriver that referenced this pull request Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants