Fix bug in ShortenUrls

Previously the method would hang in the event of an error.