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

breaking: tighten up error handling #11289

Merged
merged 31 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
64565c0
breaking: tighten up error handling
dummdidumm Dec 13, 2023
fddc54f
how did this happen
dummdidumm Dec 13, 2023
7613649
fix tests
dummdidumm Dec 13, 2023
5bf57fb
lint
dummdidumm Dec 13, 2023
34acad2
Merge branch 'version-2' into tighten-up-error-handling
dummdidumm Dec 13, 2023
ae79081
Merge branch 'version-2' into tighten-up-error-handling
dummdidumm Dec 13, 2023
067c3fa
types
dummdidumm Dec 13, 2023
43e7d2e
Merge branch 'version-2' into tighten-up-error-handling
dummdidumm Dec 13, 2023
a5da208
adjust wording (is this even a breaking change now?)
dummdidumm Dec 13, 2023
8f0fbab
adjust
dummdidumm Dec 13, 2023
6d77aa5
pass status and message to handleError
dummdidumm Dec 13, 2023
c1c280c
merge
Rich-Harris Dec 13, 2023
da81262
Apply suggestions from code review
dummdidumm Dec 13, 2023
e4c96b7
lint
dummdidumm Dec 13, 2023
e5ad6f1
Update documentation/docs/30-advanced/20-hooks.md
Rich-Harris Dec 13, 2023
a291b70
Merge branch 'version-2' into tighten-up-error-handling
Rich-Harris Dec 13, 2023
f75abdc
lint
Rich-Harris Dec 13, 2023
bbe2c5d
simplify example
Rich-Harris Dec 13, 2023
7f5df13
tweak docs
Rich-Harris Dec 13, 2023
877605f
Update documentation/docs/30-advanced/20-hooks.md
Rich-Harris Dec 13, 2023
99b54e4
Merge branch 'tighten-up-error-handling' of github.com:sveltejs/kit i…
Rich-Harris Dec 13, 2023
824198d
various tweaks. we can be less duplicative i think
Rich-Harris Dec 13, 2023
7ecbca5
tweak
Rich-Harris Dec 13, 2023
24bdfd9
tweak
Rich-Harris Dec 13, 2023
c1265d8
handle too large body after streaming has started
Rich-Harris Dec 13, 2023
452e264
cancel stream from the inside if content-length exceeds limit
Rich-Harris Dec 13, 2023
5a914a2
remove unnecessary try-catch, bump adapter-node/adapter-vercel majors
Rich-Harris Dec 13, 2023
95bb358
migration docs
Rich-Harris Dec 13, 2023
b24e8eb
tweak/fix tests
Rich-Harris Dec 13, 2023
d31afbb
fix more
Rich-Harris Dec 13, 2023
231f212
more
Rich-Harris Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cancel stream from the inside if content-length exceeds limit
  • Loading branch information
Rich-Harris committed Dec 13, 2023
commit 452e264075b24754a6f6985fdda228e18ecf7196
28 changes: 13 additions & 15 deletions packages/kit/src/exports/node/index.js
Original file line number Diff line number Diff line change
@@ -22,19 +22,6 @@ function get_raw_body(req, body_size_limit) {
return null;
}

let length = content_length;

if (body_size_limit) {
if (!length) {
length = body_size_limit;
} else if (length > body_size_limit) {
throw {
status: 413,
message: `Received content-length of ${length}, but only accept up to ${body_size_limit} bytes.`
};
}
}

if (req.destroyed) {
const readable = new ReadableStream();
readable.cancel();
@@ -46,6 +33,17 @@ function get_raw_body(req, body_size_limit) {

return new ReadableStream({
start(controller) {
if (body_size_limit !== undefined && content_length > body_size_limit) {
const error = new SvelteKitError(
413,
'Payload Too Large',
`Content-length of ${content_length} exceeds limit of ${body_size_limit} bytes.`
);

controller.error(error);
return;
}

req.on('error', (error) => {
cancelled = true;
controller.error(error);
@@ -60,11 +58,11 @@ function get_raw_body(req, body_size_limit) {
if (cancelled) return;

size += chunk.length;
if (size > length) {
if (size > content_length) {
cancelled = true;

const constraint = content_length ? 'content-length' : 'BODY_SIZE_LIMIT';
const message = `request body size exceeded ${constraint} of ${length}`;
const message = `request body size exceeded ${constraint} of ${content_length}`;

const error = new SvelteKitError(413, 'Payload Too Large', message);
controller.error(error);