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

Added a getStatusCode method. #28

Merged
merged 2 commits into from
Oct 27, 2019

Conversation

o0Ignition0o
Copy link
Contributor

this should fix #27

Please let me know if there's anything I can do to improve the pull request :)

@o0Ignition0o o0Ignition0o force-pushed the master branch 2 times, most recently from cc507cf to 528aca9 Compare December 7, 2018 10:21
@luzlab
Copy link

luzlab commented Feb 28, 2019

Can we please merge this or PR29 to get the typescript enums?

@prettymuchbryce
Copy link
Owner

My only issue with this change is that currently this project is not compiled. This means using features like Array.find and Object.entries without a polyfill could break browser compatibility.

https://caniuse.com/#feat=array-find

@o0Ignition0o
Copy link
Contributor Author

Oh I understand, do you think using a for loop instead is the way to go ? if so i can edit it today :)

@o0Ignition0o
Copy link
Contributor Author

Using a for loop + rebased as required :)

@prettymuchbryce
Copy link
Owner

This looks better. We still need to add this to the TS definition file, and probably some mention in the README as well.

@o0Ignition0o
Copy link
Contributor Author

o0Ignition0o commented Mar 8, 2019 via email

index.js Show resolved Hide resolved
README.md Outdated
@@ -26,6 +26,9 @@ response
.send({
error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
});

response.status(HttpStatus.getStatusCode('No Content'))
Copy link
Owner

Choose a reason for hiding this comment

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

Can you format these with the line breaks like the others?

README.md Outdated
@@ -107,14 +110,22 @@ response
.send({
error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
})

response
.status(getStatusCode('No Content')
Copy link
Owner

@prettymuchbryce prettymuchbryce Mar 12, 2019

Choose a reason for hiding this comment

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

How about we just use internal server error instead of no content like the example above?

@@ -384,5 +384,13 @@ export declare enum HTTP_STATUS {
* Convert the numeric status code to its appropriate title.
* @param statusCode One of the available status codes in this package
* @returns {String} The associated title of the passed status code
* @throws {Error} The status code does not exist
Copy link
Owner

Choose a reason for hiding this comment

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

Nice catch. 👍

index.d.ts Outdated
* Convert the status code title to its appropriate numeric value
* @param statusText One of the available status texts in this package
* @returns {Number} The associated status code of the passed status text
* @throws {Error} The status text does not exist
Copy link
Owner

Choose a reason for hiding this comment

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

I think you forgot to close this comment.

index.d.ts Outdated
*/
export declare function getStatusText(statusCode: number): string;

/**
* Convert the status code title to its appropriate numeric value
Copy link
Owner

Choose a reason for hiding this comment

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

I have some problem with the word "title" in these comments. We should refer to them consistently as "status code" and "status text".

In fact the IETF spec calls it a "Reason Phrase" so ideally we could change all of the comments from "title" -> "reason phrase".

The reason-phrase element exists for the sole purpose of providing a
   textual description associated with the numeric status code, mostly
   out of deference to earlier Internet application protocols that were
   more frequently used with interactive text clients.  A client SHOULD
   ignore the reason-phrase content.

@o0Ignition0o
Copy link
Contributor Author

o0Ignition0o commented Mar 16, 2019

Thanks a lot for such a thorough code review. I think I have addressed most of the concerns :)

I chose not to rename the getStatusText function name to getReasonPhrase because that would be a breaking change, but I can change it if you want to :)

By the way I was skimming over the HTTP status codes and it seems like the 500 Reason phrase is "Internal Server Error" whereas we here refer to it as "Server Error".

As stated in the IETF spec, a client should ignore the reason-phrasse content so it's probably not a big deal, plus we probably wouldn't want to cause a breaking change ^^

@justinmchase
Copy link

Can we merge this now please?

@prettymuchbryce prettymuchbryce merged commit 6677afd into prettymuchbryce:master Oct 27, 2019
@prettymuchbryce
Copy link
Owner

Sorry for the delay.

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.

Could we have a method to go from status text to status code?
4 participants