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

[fix] Handle 4xx and 5xx statuses without requiring Error instance #1811

Merged
merged 11 commits into from
Jul 15, 2021

Conversation

damain
Copy link
Contributor

@damain damain commented Jul 2, 2021

This PR fixes #1161

It checks if loaded.status is between 400 & 599 and if no loaded.error is sent it creates a message for each status and returns the status and message

It includes messages for the following statuses 400, 401, 403, 404, 409, 500
Any other statuses are defaulted to 500

One failing test for a 401 status is included.
If any other statuses or tests need to be added let me know and I'll get it done.

@changeset-bot
Copy link

changeset-bot bot commented Jul 2, 2021

🦋 Changeset detected

Latest commit: 7792c74

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@benmccann benmccann changed the title fix: error status codes [fix] error status codes Jul 3, 2021
@benmccann
Copy link
Member

Let's remove all the default error messages (which means you can ignore most of my comments as they'll no longer be relevant). It will make the client bundle too large since they're used on the client:

packages/kit/src/runtime/client/renderer.js:import { normalize } from '../load.js';

Also, you'll need to make Lint pass on the CI and add a changeset

@damain
Copy link
Contributor Author

damain commented Jul 8, 2021

Let's remove all the default error messages (which means you can ignore most of my comments as they'll no longer be relevant). It will make the client bundle too large since they're used on the client:

packages/kit/src/runtime/client/renderer.js:import { normalize } from '../load.js';

Also, you'll need to make Lint pass on the CI and add a changeset

Should it have a default error included

return {
    status,
    error: new Error('Error Object Not Specified')
};

@benmccann
Copy link
Member

I'd probably not include any type of default error message

@damain
Copy link
Contributor Author

damain commented Jul 9, 2021

I am thinking since the status was between 4xx and 5xx an error should exist because the error is needed in order for the node not to load.
Since one was not sent we can do a warn to the console return the status and an empty error

console.warn(' "status" property was returned from load() without an error ')
return {
    status,
    error: new Error()
};

@damain
Copy link
Contributor Author

damain commented Jul 10, 2021

I am thinking since the status was between 4xx and 5xx an error should exist because the error is needed in order for the node not to load.
Since one was not sent we can do a warn to the console return the status and an empty error

console.warn(' "status" property was returned from load() without an error ')
return {
    status,
    error: new Error()
};

Any feedback on this?

@benmccann
Copy link
Member

Yeah. Could either return empty or just return Internal Server Error

@damain
Copy link
Contributor Author

damain commented Jul 10, 2021

I updated the code it was working but the new client test is failing. I will have to work on this some more to get this working.
(The client test from #1355 was also failing)

@damain
Copy link
Contributor Author

damain commented Jul 12, 2021

I am running into a sticking point with solving this. On the server it returns the correct status and loads the error template but on the client side it doesn't load the error template unless an error is passed from load.

I also noted that even though the error is passed, response.status() on the client is always 200. However the node itself seems to have the correct status and it can be passed in as props.

At first I thought the issue could be in client/renderer.js where it only checks for error to see if it should generate the error template. I changed all the checks for error to also check status and that did not solve it.

@benmccann
Copy link
Member

I added more information on how to debug the tests here: #1900

@damain
Copy link
Contributor Author

damain commented Jul 14, 2021

I added more information on how to debug the tests here: #1900

are you sure #1900 is the correct link

@benmccann
Copy link
Member

Yes. But now that it's checked in, you can just view the updated README: https://github.com/sveltejs/kit#testing

@damain damain requested a review from benmccann July 15, 2021 00:40
@damain damain requested a review from benmccann July 15, 2021 12:44
@benmccann benmccann changed the title [fix] error status codes [fix] Handle 4xx and 5xx statuses without requiring Error instance Jul 15, 2021
@benmccann benmccann merged commit 41da1eb into sveltejs:master Jul 15, 2021
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.

load function does not respect returned error status codes
2 participants