handleError for SvelteKit 3: ids only for unknown errors, compact 404 log line; error page suggestions prefer the real parent over the section
All checks were successful
Deploy production / deploy (push) Successful in 1m10s
All checks were successful
Deploy production / deploy (push) Successful in 1m10s
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import type { HandleClientError } from '@sveltejs/kit';
|
||||
|
||||
// Errors thrown while rendering/loading in the browser: same shape as the server (short id,
|
||||
// generic message) so the error page looks the same either way.
|
||||
export const handleError: HandleClientError = ({ error, status, message }) => {
|
||||
if (status === 404) return { message: 'Not Found' };
|
||||
// Unknown errors thrown while loading/rendering in the browser get an id like on the server, so
|
||||
// the error page looks the same either way. App and framework errors keep their defaults.
|
||||
export const handleError: HandleClientError = (input) => {
|
||||
if (input.kind !== 'unknown') return;
|
||||
const id = crypto.randomUUID().slice(0, 8);
|
||||
console.error(`[error ${id}] ${status}`, error);
|
||||
return { message: status >= 500 ? 'Internal Error' : message, id };
|
||||
console.error(`[error ${id}]`, input.error);
|
||||
return { id };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user