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

Add HTTP Status Codes ENUM #1439

Closed
Kapsonfire-DE opened this issue May 13, 2021 · 4 comments
Closed

Add HTTP Status Codes ENUM #1439

Kapsonfire-DE opened this issue May 13, 2021 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@Kapsonfire-DE
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When giving proper error codes in response of endpoints/loads sometimes I have to google for the correct code, like PAYMENT_REQUIRED, BAD_REQUEST and some other things. Most Codes are well known, others not. To make it easier implementing a ENUM is a good solution.

Describe the solution you'd like
I'd like to get the Status Code ENUMs integrated in svelte kit.

Describe alternatives you've considered
I started using https://www.npmjs.com/package/http-status-codes package.

export async function post(request) {
    let ct = request.headers['content-type'] ?? '';
    if(ct !== 'application/json') {
        return {
            status: StatusCodes.BAD_REQUEST,
            body: ReasonPhrases.BAD_REQUEST
        };
    }
    let data = request.body;
    return {
        body: data
    }
}

A decision has to be made.
1)
I can create a PR and add it to svelte kit.
2)
A already written npm package could be put into the package.json.
3)
Leave it to the user like current state.

@dummdidumm
Copy link
Member

Personally I'm against adding this as a dependency or adding this built-in. I could imagine adding this to the docs somewhere though.

@Kapsonfire-DE
Copy link
Contributor Author

@dummdidumm what are the reasons, why you are against it. I could think of the additional footprint on client.
But to solve this the ENUM could be replaced on preprocess

@rmunn
Copy link
Contributor

rmunn commented May 17, 2021

I'd be against this for two reasons:

  1. There's already an NPM package (probably several packages) that can solve this issue completely, for those who want it, and
  2. Many people won't want to add the package because they're only using well-known codes like 200 and 404.

So there's no need to add this into Svelte-Kit core. The people who want this, and are willing to pay the cost of an extra 3.5 kB sent to the client, can use the http-status-codes package. Those who can't easily remember the status codes but don't want an extra 3.5 kB bundle size can create a single file with constants for just the ones they use, or even just put a comment on every unusual status code they use (status: 202 // ACCEPTED) to make it easy. And finally, those who don't need it won't have to pay an extra 3.5 kB size cost.

@dummdidumm dummdidumm added the documentation Improvements or additions to documentation label May 17, 2021
@benmccann
Copy link
Member

I'm going to close this for the reasons given in the above comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants