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

allow statusCodes to be passed as an array or a set #115

Merged
merged 4 commits into from
Jul 28, 2020
Merged

allow statusCodes to be passed as an array or a set #115

merged 4 commits into from
Jul 28, 2020

Conversation

redxtech
Copy link
Contributor

Before this PR, you were only able to specify a single acceptable status code, as the type check for args was only for number.

If you passed an array of status codes it would attempt to set them as the headers, which doesn't work.

With this PR, you can now pass either an array or a set of the statusCodes that will be accepted.

I have included tests in the like of the status 201 test, so that should cover it.

@redxtech
Copy link
Contributor Author

I have just realized that you can of course just pass the status' as multiple args, so this isn't really necessary, but I do feel that this is a very minimal addition to the codebase that adds some flexibility, which seems to fit with this project.

@mikeal
Copy link
Owner

mikeal commented Jul 28, 2020

At first I thought “we might want to give some meaning to Array as an input type later on that this will preclude.” But having thought about it a bit we could always do type checks inside of the array for other features since I doubt any of those features would be specific to “an array of numbers” so I’m actually fine with adding this.

This allows for some nicer expressions because you don’t have to use the spread operator to use a programmatically generated list of status codes.

@mikeal mikeal merged commit 83d8ae3 into mikeal:master Jul 28, 2020
@redxtech
Copy link
Contributor Author

Yeah, that's pretty much exactly what I was thinking.

Passing an array will be much nicer than what I have currently in my project:
...(typeof status === 'number' ? [status] : status)

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.

None yet

2 participants