Hooks and Error Handling
While it can be incredibly useful to make API requests from any page, imagine the nuisance of attempting to authenticate a user for an external API on every page. It may be possible to create a custom helper that adds specific headers or cookies to every single request to assist with this. Fortunately for us, SvelteKit provides methods to manipulate Request and Response objects across the entirety of a framework. It does so with what are called hooks. These hooks can be incredibly powerful to manage data that flows in and out of our application. They can also be helpful for managing errors. Since our previous encounters with error handling have been so brief, we’ll examine error handling a little closer after covering hooks.
In this chapter, we will cover the following topics:
- Using Hooks
- Error Handling
As a practical example, we’ll build a simple interface allowing us to star the official SvelteKit repository on GitHub....