예제 #1
0
        public async Task <string> GetURLAsync(string shortUrl)
        {
            Guard.Against.NullOrEmpty(shortUrl, "Short URL");
            Guard.Against.OutOfRange(shortUrl.Length, "Short URL", _config.ShortUrlLength, _config.ShortUrlLength);
            URL res = null;

            try {
                ShortURL id = new ShortURL(AddBase64Strings(shortUrl));
                res = await _urlRepository.GetByIdAsync(id);

                if (res == null)
                {
                    throw new URLNotFoundException(shortUrl);
                }
                return(res.Value);
            }catch (Exception excp)
            {
                _logger.LogError(excp, $"Error fetching url with shortURL: {shortUrl}.");
                res = null;
            }
            return(res?.Value);
        }