public async Task <IWatcherCheckResult> ExecuteAsync() { var baseUrl = _configuration.Uri.ToString(); var fullUrl = _configuration.Request.GetFullUrl(baseUrl); try { var response = await _httpService.ExecuteAsync(baseUrl, _configuration.Request, _configuration.Timeout); var isValid = HasValidResponse(response); if (!isValid) { return(WebWatcherCheckResult.Create(this, false, _configuration.Uri, _configuration.Request, response, $"Web endpoint: '{fullUrl}' has returned an invalid response with status code: {response.StatusCode}.")); } return(await EnsureAsync(fullUrl, response)); } catch (TaskCanceledException exception) { return(WebWatcherCheckResult.Create(this, false, _configuration.Uri, _configuration.Request, null, $"A connection timeout occurred while trying to access the Web endpoint: '{fullUrl}'.")); } catch (Exception exception) { throw new WatcherException($"There was an error while trying to access the Web endpoint: '{fullUrl}'.", exception); } }
private async Task <IWatcherCheckResult> EnsureAsync(string fullUrl, IHttpResponse response) { var isValid = true; if (_configuration.EnsureThatAsync != null) { isValid = await _configuration.EnsureThatAsync?.Invoke(response); } isValid = isValid && (_configuration.EnsureThat?.Invoke(response) ?? true); return(WebWatcherCheckResult.Create(this, isValid, _configuration.Uri, _configuration.Request, response, $"Web endpoint: '{fullUrl}' has returned a response with status code: {response.StatusCode}.")); }