In this blog post am going to explain how the Twitter Followers Insight app handles error which occurs when when no query is passed to the “Search” function i.e., when the search is proceeded with an empty query.
How to handle the Exception
In such cases, I have used SNACKBAR / TOAST. Snackbar / Toast is used to popup an error notification on the screen when an exception occurs.
Script for Snackbar / Toast:
In the below script, initially the error is set to null i.e., no error. The “showError” function is which is being called when there occurs a situation of no query or an empty query. The function below helps to show an error popup which only shows till a time limit.
In this script, it checks whether the query passed is undefined or empty. If yes, then the error message which was null earlier is changed and that error is showed up on the screen to the end user. Snackbars animate upwards from the edge of the screen.
- More about Snackbar at: https://material.io/guidelines/components/snackbars-toasts.html#
- How to use Snackbar at: https://kimsereyblog.blogspot.in/2016/11/how-to-use-snackbar-api-in.html
- Tutorial about Snackbar at: https://www.w3schools.com/howto/howto_js_snackbar.asp