validation: throw exception if content-type is missing
See original GitHub issueDescribe the bug I get this error since upgrading to SK next-81 (also happens on 83). This possibly happens because of an API route with POST requests like so:
import fetch from 'node-fetch'
/**
* Load data from API
*/
// Get results from a POST request
export async function post ({ headers, query, body, params, ...rest }) {
try {
const res = await fetch(`https://${import.meta.env.VITE_SANITY_ID}.apicdn.sanity.io/v1/data/query/production?query=${encodeURIComponent(body)}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${import.meta.env.VITE_SANITY_TOKEN}`,
}
})
const data = await res.json()
return {
status: 200,
body: data
}
}
catch (error) {
return {
status: error.status || 500,
body: error.message || error.text || `Can't fetch query`
}
}
}
Logs
Cannot read property 'split' of undefined
TypeError: Cannot read property 'split' of undefined
at parse_body (file:///site/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.83_svelte@3.37.0+vite@2.1.5/node_modules/@sveltejs/kit/dist/ssr.js:1330:60)
at ssr (file:///site/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.83_svelte@3.37.0+vite@2.1.5/node_modules/@sveltejs/kit/dist/ssr.js:1448:9)
at fetch (file:///site/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.83_svelte@3.37.0+vite@2.1.5/node_modules/@sveltejs/kit/dist/ssr.js:697:30)
Information about your SvelteKit Installation:
Diagnostics
System:
OS: macOS 11.2.3
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 480.96 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.14.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.7.6 - /usr/local/bin/npm
Browsers:
Brave Browser: 90.1.23.71
Firefox: 84.0.1
Safari: 14.0.3
npmPackages:
@sveltejs/kit: next => 1.0.0-next.83
svelte: ^3.37.0 => 3.37.0
vite: ^2.1.5 => 2.1.5
Severity Well, it kind of blocks the whole app 🙈
Issue Analytics
- State:
- Created 2 years ago
- Comments:25 (19 by maintainers)
Top Results From Across the Web
Intercept @RequestHeader exception for missing header
In your controller, you can throw an exception if the header provided is invalid. @RequestMapping(value = "/{blabla}", method = RequestMethod.POST) @ ...
Read more >ElasticSearch, ingest-attachment error - Validation Failed: 1
Am trying to indexing my pdf file from local path via java code. During indexing am getting the below error. Please find my...
Read more >Validation errors appear as Marshmallow Exceptions and ...
When doing a POST with invalid data I get a HTTP/1.1 200 OK Connection: keep-alive Content-Encoding: gzip Content-Type: application/json; ...
Read more >What is .Net Core Web Api Model Validation error ...
I have purposely generated this error. However, when model state is not valid it returns a response that's attached bellow based on the ......
Read more >Centralized exception handling and request validation in ...
Centralized exception handling and request validation in ASP.NET Core ... When this member is not present, its value is assumed to be.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Rich-Harris can you please reopen this issue and rollback the commit made yesterday? I’ve just tested my code with the new SvelteKit version (next.95) and the problem still persists. Seems like the fix which has been done yesterday has no effect and has been done in a wrong place of the code. Please, see the picture bellow. It all doesn’t make much sense to me right now, but that’s just how things are.
In case you reopen the issue I’m willing to try and put together steps to reproduce the problem. It seems to be a rather tricky one. It’s prolly gonna take me a while to put all the steps together with enough details. So, please, bear with me.
I just wrote a big paragraph here about what I would consider the ideal API which I then erased, because I realized it was more complicated than I was thinking it was. I think it would be nice if endpoints had access to the request body before it’s even been uncompressed, because this might be a proxy to some other endpoint elsewhere, and we don’t want to decompress that data, just send it along as-is.
Do we need three types of bodies? Entirely-raw, content-encoding-decoded, and content-type-decoded?