0
0
Svelteframework~20 mins

Error pages (+error.svelte) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Error Page Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this +error.svelte component display when an error occurs?
Consider this +error.svelte component in a SvelteKit app:
  <script>
export let error;
export let status;
</script>
<h1>Error {status}</h1>
<p>{error.message}</p>

What will the user see if the server returns a 404 error with message "Not Found"?
A<h1>Error 500</h1><p>Not Found</p>
B<h1>Error 404</h1><p>Not Found</p>
C<h1>Error 404</h1><p>Internal Server Error</p>
D<h1>Error</h1><p>Not Found</p>
Attempts:
2 left
💡 Hint
The status prop shows the HTTP status code, and error.message shows the error text.
📝 Syntax
intermediate
1:30remaining
Which +error.svelte code snippet correctly exports the error and status props?
You want to access the error and status in your +error.svelte component. Which code snippet is correct?
A<script> export default { error, status }; </script>
B<script> export const error; export const status; </script>
C<script> export let error; export let status; </script>
D<script> let error; let status; </script>
Attempts:
2 left
💡 Hint
Props must be declared with 'export let' in Svelte components.
🔧 Debug
advanced
2:30remaining
Why does this +error.svelte component fail to display the error message?
Given this +error.svelte code:
<script>
  export let error;
  export let status;
</script>
<h1>Error {status}</h1>
<p>{error.msg}</p>

The error message does not show up. What is the cause?
AThe status prop is not exported correctly, causing the error message to fail.
BThe error message is not displayed because the <p> tag is missing a closing tag.
CThe component must use $error to access the error object, not 'error'.
DThe property 'msg' does not exist on the error object; it should be 'message'.
Attempts:
2 left
💡 Hint
Check the property name used to access the error text.
state_output
advanced
2:00remaining
What is the output when +error.svelte receives a 500 status with a custom error message?
This +error.svelte component:
<script>
  export let error;
  export let status;
</script>
<h1>Oops! Error {status}</h1>
<p>{error.message}</p>

Receives props: status = 500, error.message = "Server crashed".
What is the rendered output?
A<h1>Oops! Error 500</h1><p>Server crashed</p>
B<h1>Oops! Error 404</h1><p>Server crashed</p>
C<h1>Error 500</h1><p>Server crashed</p>
D<h1>Oops! Error 500</h1><p>Internal Server Error</p>
Attempts:
2 left
💡 Hint
The component uses the status and error.message props directly in the output.
🧠 Conceptual
expert
3:00remaining
Which statement about +error.svelte in SvelteKit is TRUE?
Choose the correct statement about the +error.svelte file in a SvelteKit project.
A+error.svelte is a special component that automatically receives 'error' and 'status' props when an error occurs during routing.
B+error.svelte must be manually imported and used in every page to handle errors.
C+error.svelte can only handle client-side errors, not server-side errors.
D+error.svelte replaces the default 404 page but cannot display custom error messages.
Attempts:
2 left
💡 Hint
Think about how SvelteKit handles errors globally.