-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[fix] handle missing server file for an action request #7958
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 missing server file for an action request #7958
Conversation
🦋 Changeset detectedLatest commit: 8491ba0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
@s3812497 is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
Thank you - I'm not sure if this is the right fix though. Looking at the linked issue, that error response should have been JSON instead - the "Accept" header clearly states that. So we should fix this on the server instead. Are there other situations besides the reproducible in the issue where you experienced this bug? |
Ah you're right. I wasn't even thinking of the Accept header. I assumed that the server was returning plain text responses for all errors because it was also failing to parse the 405 error response when no actions exist (this was what I was trying to fix originally). I think it's this line that's causing it?. Should the server return a JSON response body in most if not all cases?
The server returns Otherwise, without a |
Interesting - thanks for investigating! The Accept header should be honored in these cases, so in the progressive enhancement case where JSON is expected for the response, it should be sent as such. |
enhance
Thanks for the guidance @dummdidumm ! I've added handling for a missing server file using the same "405 POST method not allowed. No actions exist for this page" response. Hopefully I've implemented this correctly. |
Thank you! Ok so this brings up another design question: Right now the response is still not JSONified, which it should be, but if we do that, it ideally should honor the |
Yup, looks much better now. What about the plain text response from the CSRF check? if (options.csrf.check_origin) {
const forbidden =
request.method === 'POST' &&
request.headers.get('origin') !== url.origin &&
is_form_content_type(request);
if (forbidden) {
const csrf_error = error(403, `Cross-site ${request.method} form submissions are forbidden`);
// handle accept: application/json
if (request.headers.get('accept') === 'application/json') {
return json(csrf_error.body, { status: csrf_error.status });
}
return new Response(csrf_error.body.message, { status: csrf_error.status });
}
} |
yeah that makes sense 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
fixes #7965
fixes #7957
405
response for an action request when no server file exists for a page.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0