Search code examples
javascripttypescriptserversveltesveltekit

How to stop execution in Svelte?


For example, in PHP it is possible to stop execution using exit();.

How do I simply stop the script from continuing?

Not shutting down the server, but ending the request and showing a blank message on the screen, like:

Script ended abruptly.


Solution

  • You can call error, which will show the +error.svelte page.

    To signal that this was due to some interruption, you can pass something via the second argument and use that information in the component via $page.error (e.g. a code to resolve or a message to show directly).