Giter Club home page Giter Club logo

Comments (7)

prettymuchbryce avatar prettymuchbryce commented on August 10, 2024

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.

JaniszM avatar JaniszM commented on August 10, 2024

First one: Http.getConstant(http.NOT_FOUND); // 'NOT_FOUND' :) It is very useful ^^

from http-status-codes.

prettymuchbryce avatar prettymuchbryce commented on August 10, 2024

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.

JaniszM avatar JaniszM commented on August 10, 2024

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.

prettymuchbryce avatar prettymuchbryce commented on August 10, 2024

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.

JaniszM avatar JaniszM commented on August 10, 2024

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.

prettymuchbryce avatar prettymuchbryce commented on August 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.