Generic error handler for js