Complete the code to import the error helper from SvelteKit.
import { [1] } from '@sveltejs/kit';
The error helper is imported from '@sveltejs/kit' to throw HTTP errors in the load function.
Complete the code to throw a 404 error with a message inside the load function.
export function load() {
throw [1](404, 'Not found');
}Use the error helper to throw HTTP errors with status code and message.
Fix the error in the load function to correctly catch and throw a 500 error.
export async function load() {
try {
const res = await fetch('/api/data');
if (!res.ok) {
throw [1](500, 'Server error');
}
return await res.json();
} catch (err) {
throw err;
}
}Use the error helper to throw HTTP errors with status code and message inside load.
Fill both blanks to throw a 401 error with a custom message and import the helper.
import { [1] } from '@sveltejs/kit'; export function load() { throw [2](401, 'Unauthorized access'); }
Import and use the error helper to throw HTTP errors with status and message.
Fill all three blanks to import error, check response status, and throw a 403 error if unauthorized.
import { [1] } from '@sveltejs/kit'; export async function load({ fetch }) { const response = await fetch('/secret'); if (!response.[2]) { throw [3](403, 'Forbidden'); } return await response.json(); }
Import error, check response.ok, and throw error with status 403 if unauthorized.