Add error handling to discover.js