Added basic error handling for getCategories()