In this episode, we tackle an issue you might have spotted if you've ever ended up with no sites left in our app. When the last site is deleted, the homepage throws an error because there's no site data to show or endpoints to list out, which clearly isn't a great user experience!
We start by looking at why this error happens, diving into the dashboard controller code and noticing that it's trying to access properties on a site object—even when there isn't one. To fix this, we add some simple checks and use ternary operators to make sure we're only trying to get endpoints when a site exists. While refreshing, we still see errors popping up, so we hunt them down elsewhere (like the SiteResource and the dashboard's header code) and fix them by making our data access optional.
Once we've resolved the errors, our dashboard is technically "fixed"—but now just looks empty when there are no sites. So, next up, we improve the user interface by wrapping the main dashboard content in a conditional template, and showing a friendly placeholder message instead. The message encourages users to add their first site, and we tweak the styles to make it look nice and clear.
By the end of the episode, you'll see how to gracefully handle empty states in your app and give users a helpful nudge in the right direction when there's nothing to show yet.