Recall & Review
beginner
What does the
json() helper do in SvelteKit?The
json() helper creates a response with JSON content and the correct Content-Type header. It formats data so the client can easily read it as JSON.Click to reveal answer
beginner
How do you use the
error() helper in SvelteKit?You call
error(status, message) to create an error response with a status code and message. This stops the request and shows an error page or message.Click to reveal answer
intermediate
Why is it better to use
json() instead of manually creating a JSON response?Because
json() automatically sets the right headers and formats the data correctly, making your code cleaner and less error-prone.Click to reveal answer
intermediate
What happens if you use
error(404, 'Not found') in a SvelteKit load function?The request stops and SvelteKit shows a 404 error page with the message 'Not found'. This helps handle missing data or pages gracefully.
Click to reveal answer
beginner
Can you customize the error message shown to users when using
error()?Yes, you provide a custom message as the second argument to
error(). This message can explain what went wrong in simple words.Click to reveal answer
What header does the
json() helper automatically set?✗ Incorrect
The
json() helper sets the Content-Type header to application/json so the client knows the response is JSON.What does
error(500, 'Server error') do in SvelteKit?✗ Incorrect
The
error() helper throws an error response with the given status and message, stopping the request.Which helper should you use to send JSON data from a SvelteKit endpoint?
✗ Incorrect
Use
json() to send JSON data with proper headers from an endpoint.If you want to stop a request and show a 404 page, which helper do you use?
✗ Incorrect
Using
error(404, 'Not found') stops the request and shows the 404 error page.What type of value does
json() expect as input?✗ Incorrect
json() expects a JavaScript object or array to convert into JSON format.Explain how and why you would use the
json() helper in a SvelteKit endpoint.Think about sending data from server to client in a clean way.
You got /4 concepts.
Describe the purpose of the
error() helper and how it affects the user experience in SvelteKit.Consider what happens when something goes wrong on the server.
You got /4 concepts.