public IActionResult Post([FromBody] TakeSceenshotsPostRequest requestsArg) { List <string> failedURLs = new List <string>(); foreach (var screenshotRequest in requestsArg.ScreenshotRequests) { var formatedUrl = UrlHelper.FormatUrl(screenshotRequest.URL); if (UrlHelper.ValidateUrl(formatedUrl) == "") { try { var screenshot = _browserDriver.TakeScreenshot(formatedUrl, screenshotRequest.FileName); _screenshotRepository.CreateScreenshot(screenshotRequest.FileName, screenshot.AsByteArray, formatedUrl); } catch (WebDriverException) { failedURLs.Add(screenshotRequest.URL); } catch (Exception) { return(StatusCode(500, "Failed to save screenshots.")); } } else { failedURLs.Add(screenshotRequest.URL); } } var response = new TakeSceenshotsPostResponse(); response.Status = failedURLs.Count == 0 ? "Success" : "Partial success"; response.FailedURLs = failedURLs; return(StatusCode(200, response)); }