Skip to content

Commit ae2f4a8

Browse files
elliott-with-the-longest-name-on-githubdummdidummRich Harris
authored
feat: improve error message for handleHttpError and handleMissingId (#9621)
* patch: Improve error message for `handleHttpError` and `handleMissingId` * chore: changest * Update .changeset/tall-bags-sparkle.md * put the message in the fallback handler * oops --------- Co-authored-by: Simon H <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 5e27d67 commit ae2f4a8

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

Diff for: .changeset/tall-bags-sparkle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: better error messages for handleable prerender failures

Diff for: packages/kit/src/core/config/index.spec.js

-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ const get_defaults = (prefix = '') => ({
105105
concurrency: 1,
106106
crawl: true,
107107
entries: ['*'],
108-
handleHttpError: 'fail',
109-
handleMissingId: 'fail',
110108
origin: 'http://sveltekit-prerender'
111109
},
112110
version: {

Diff for: packages/kit/src/core/config/options.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,33 @@ const options = object(
201201
return input;
202202
}),
203203

204-
handleHttpError: validate('fail', (input, keypath) => {
205-
if (typeof input === 'function') return input;
206-
if (['fail', 'warn', 'ignore'].includes(input)) return input;
207-
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
208-
}),
204+
handleHttpError: validate(
205+
(/** @type {any} */ { message }) => {
206+
throw new Error(
207+
message +
208+
`\nTo suppress or handle this error, implement \`handleHttpError\` in https://kit.svelte.dev/docs/configuration#prerender`
209+
);
210+
},
211+
(input, keypath) => {
212+
if (typeof input === 'function') return input;
213+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
214+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
215+
}
216+
),
209217

210-
handleMissingId: validate('fail', (input, keypath) => {
211-
if (typeof input === 'function') return input;
212-
if (['fail', 'warn', 'ignore'].includes(input)) return input;
213-
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
214-
}),
218+
handleMissingId: validate(
219+
(/** @type {any} */ { message }) => {
220+
throw new Error(
221+
message +
222+
`\nTo suppress or handle this error, implement \`handleMissingId\` in https://kit.svelte.dev/docs/configuration#prerender`
223+
);
224+
},
225+
(input, keypath) => {
226+
if (typeof input === 'function') return input;
227+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
228+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
229+
}
230+
),
215231

216232
origin: validate('http://sveltekit-prerender', (input, keypath) => {
217233
assert_string(input, keypath);

0 commit comments

Comments
 (0)