Comments (7)
I'm not sure I understand your request. You want a function that takes the status code, and returns a string representation of the constant ?
Like this ?
Http.getConstant(http.NOT_FOUND); // 'NOT_FOUND'
Or are you asking for a function that returns the message ? This already exists as getStatusText()
.
Http.getStatusText(http.NOT_FOUND); // 'Not Found'
from http-status-codes.
First one: Http.getConstant(http.NOT_FOUND); // 'NOT_FOUND'
:) It is very useful ^^
from http-status-codes.
I'm having trouble understanding the use case for this. Can you explain how it's useful ? The constant points to the status code, which you must already know if you're calling this function with it.
from http-status-codes.
Yes, it's weird a little. But, let's say you have convetion for errors like this:
{
errorStatus: 404,
errorCode: NOT_FOUND,
description: "something blablabla"
}
Then you need code and constant. So this is very useful to have it in one place :) I can of course convert constant to string but it is much more convenient to have it in one object.
Now this is more clear?
from http-status-codes.
I'm still having trouble understanding. In your case the errorCode and errorStatus would be the same value, as NOT_FOUND
is a variable with the value of 404. Why do you need the constant variable name (NOT_FOUND
) in string form ?
Maybe it's worth noting that these constant names are not part of any spec. They are somewhat arbitrary.
from http-status-codes.
Ok, I think this have no sense because for me string name of code is the same like getStatusText for you. So In that case someone else will come and say he want another method with another standardised text for him. So I will just leave My own getStatusText constants in other file and use it :)
from http-status-codes.
Yes I think your conclusion is correct. Just to clarify, getStatusText()
returns the "Reason-Phrase" which is documented as part of the HTTP specification here. It's not a matter of anyone's preference or opinion, but instead trying to follow the recommendation of the specification.
from http-status-codes.
Related Issues (20)
- Feature Request: add esm support HOT 3
- Add 451 Unavailable For Legal Reasons
- Optional Addition of Test Coverage for Consistency HOT 1
- Built types importing from codes file not in build folder HOT 1
- 2.1.1 breaking changes on StatusCodes HOT 1
- Library size has tripled since v2 HOT 12
- ReferenceError: __dirname is not defined HOT 7
- Mark the module as side-effect-free HOT 3
- not working in react-native (__dirname not defined) HOT 3
- 451 Status Code Missing From Typescript Definition File - Missing Library Root Export HOT 1
- getStatusCode should also accept constants HOT 1
- Provide an union of type StatusCode.
- Audit vulnerabilities detected in the httpstatuscodes project on Tag: v2.1.4 HOT 1
- Release a new npm package ver with MISDIRECTED_REQUEST, please HOT 2
- No release information for v2.2.0 HOT 2
- Missing status codes for newtork failures HOT 6
- Rollup: `this` has been rewritten to `undefined`
- Reorder of the status codes enums exported HOT 1
- Add non-throwing variants HOT 1
- Add description to status codes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-status-codes.