Skip to content

Commit

Permalink
feat: improve error message for handleHttpError and `handleMissingI…
Browse files Browse the repository at this point in the history
…d` (#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 <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Rich Harris <git@rich-harris.dev>
  • Loading branch information
3 people committed Apr 17, 2023
1 parent 5e27d67 commit ae2f4a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-bags-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: better error messages for handleable prerender failures
2 changes: 0 additions & 2 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ const get_defaults = (prefix = '') => ({
concurrency: 1,
crawl: true,
entries: ['*'],
handleHttpError: 'fail',
handleMissingId: 'fail',
origin: 'http://sveltekit-prerender'
},
version: {
Expand Down
36 changes: 26 additions & 10 deletions packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,33 @@ const options = object(
return input;
}),

handleHttpError: validate('fail', (input, keypath) => {
if (typeof input === 'function') return input;
if (['fail', 'warn', 'ignore'].includes(input)) return input;
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
}),
handleHttpError: validate(
(/** @type {any} */ { message }) => {
throw new Error(
message +
`\nTo suppress or handle this error, implement \`handleHttpError\` in https://kit.svelte.dev/docs/configuration#prerender`
);
},
(input, keypath) => {
if (typeof input === 'function') return input;
if (['fail', 'warn', 'ignore'].includes(input)) return input;
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
}
),

handleMissingId: validate('fail', (input, keypath) => {
if (typeof input === 'function') return input;
if (['fail', 'warn', 'ignore'].includes(input)) return input;
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
}),
handleMissingId: validate(
(/** @type {any} */ { message }) => {
throw new Error(
message +
`\nTo suppress or handle this error, implement \`handleMissingId\` in https://kit.svelte.dev/docs/configuration#prerender`
);
},
(input, keypath) => {
if (typeof input === 'function') return input;
if (['fail', 'warn', 'ignore'].includes(input)) return input;
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
}
),

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

0 comments on commit ae2f4a8

Please sign in to comment.