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

[GitHub] Error message customisation for all status codes #1888

Merged
merged 19 commits into from
Aug 14, 2018

Conversation

PyvesB
Copy link
Member

@PyvesB PyvesB commented Aug 10, 2018

This pull request arises from this discussion and is inspired by @RedSparr0w's suggestion in those comments.

The idea is to allow callers of the checkErrorResponse to provide a custom error message for all status codes, not just the 404 one.

I also converted the remaining assert.equals usages to expect in error-helper.spec.js.

@shields-ci
Copy link

shields-ci commented Aug 10, 2018

Warnings
⚠️

This PR modified service code for apm but not its test code. That's okay so long as it's refactoring existing code.

⚠️

This PR modified service code for appveyor but not its test code. That's okay so long as it's refactoring existing code.

⚠️

This PR modified service code for npm but not its test code. That's okay so long as it's refactoring existing code.

Messages
📖

✨ Thanks for your contribution to Shields, @PyvesB!

Generated by 🚫 dangerJS

@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth, Shared helpers label Aug 10, 2018
@PyvesB PyvesB changed the title [GitHub] Error message customisation for all status codes [GitHub] Error message customisation for all status codes - WIP Aug 10, 2018
@paulmelnikow
Copy link
Member

paulmelnikow commented Aug 10, 2018

Hey, thanks for taking this on. I'll wait to leave comments 'till you're ready. There is a small conflict between this and #1890, so whichever goes in second will need a little bit of updating.

@PyvesB PyvesB changed the title [GitHub] Error message customisation for all status codes - WIP [GitHub] Error message customisation for all status codes Aug 10, 2018
@PyvesB
Copy link
Member Author

PyvesB commented Aug 10, 2018

Okay, I think I'm mostly done here, I'm happy to hear some feedback and thoughts at this point! 👍

Copy link
Member

@RedSparr0w RedSparr0w left a comment

Choose a reason for hiding this comment

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

Nice work,
Changes all look great to me!
👍

assert.equal('inaccessible', badgeData.text[1])
assert.equal('red', badgeData.colorscheme)
expect(checkErrorResponse(badgeData, 'something other than null', {})).to.be
.true
Copy link
Member

Choose a reason for hiding this comment

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

Is this on a new line because of prettier/eslint?
I feel like it would look better on 1 line, but i'm fine with it either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe this is due to Prettier.

checkErrorResponse({ text: [] }, null, { statusCode: 200 })
)
expect(checkErrorResponse({ text: [] }, null, { statusCode: 200 })).to.be
.false
Copy link
Member

Choose a reason for hiding this comment

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

Is this on a new line because of prettier/eslint?
I feel like it would look better on 1 line, but i'm fine with it either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe this is due to Prettier.

@@ -1,19 +1,18 @@
'use strict'

const { NotFound, InvalidResponse } = require('../services/errors')
const defaultErrorMessages = {
404: 'not found',
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be worth while adding a few more defaults?

401: Unauthorized
403: Forbidden
408: Request Timeout
429: Too Many Requests
500: Internal Server Error

Maybe some others too, not really sure which would be the more common ones we would possibly encounter

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there an easy way to tell the CI server to run all service tests? If we start adding additional defaults, there is a risk of breaking existing tests.

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe there is, but it would likely fail due to timeouts.
Good point, i'm fine with just having 404 default for now, until we see a need for more.

Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

Just one comment; otherwise looks good!

}
return standardCheckErrorResponse(badgeData, err, res, notFoundMessage)
errorMessages[404] = notFoundMessage
errorMessages[422] = notFoundMessage
Copy link
Member

Choose a reason for hiding this comment

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

Rather than mutate the inputs, it's probably better to create a new object:

{404: notFoundMessage, 422: notFoundMessage, ...errorMessages}

Or maybe you want it in reverse:

{...errrorMessages, 404: notFoundMessage, 422: notFoundMessage}

paulmelnikow
paulmelnikow previously approved these changes Aug 11, 2018
@PyvesB
Copy link
Member Author

PyvesB commented Aug 12, 2018

I have rebased as #1890 was causing conflicts. Would @paulmelnikow or @RedSparr0w like to have one last look before I merge?

@PyvesB
Copy link
Member Author

PyvesB commented Aug 12, 2018

It occurred to me that the new service base hadn't been updated, this should now be fixed.

RedSparr0w
RedSparr0w previously approved these changes Aug 13, 2018
Copy link
Member

@RedSparr0w RedSparr0w left a comment

Choose a reason for hiding this comment

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

👍 Changes are looking great!

const badgeData = { text: [] }
expect(
checkErrorResponse(badgeData, null, { statusCode: 422 }, 'repo not found')
checkErrorResponse(badgeData, null, { statusCode: 422 }, 'user not found')
Copy link
Member

Choose a reason for hiding this comment

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

Should this statusCode be 404?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes indeed!

@PyvesB PyvesB dismissed stale reviews from RedSparr0w and paulmelnikow via a520570 August 13, 2018 17:51
@PyvesB PyvesB requested a review from RedSparr0w August 13, 2018 18:26
@PyvesB PyvesB merged commit b0070ff into badges:master Aug 14, 2018
@shields-deployment
Copy link

This pull request was merged to master branch. Now this change is waiting for deployment.
Deploys usually happen every few weeks. After deployment changes are copied to gh-pages branch.

This badge displays deployment status:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants