Better way to handle setTimeout() failure