public async Task <IActionResult> RegisterUser([FromBody] UserInfo userInfo) { HttpResponseMessage response; PolicyDefinitions polly = new PolicyDefinitions(); var sqlBreakerPolicy = polly.sqlCircuitBreakerPolicy(); try { if (ModelState.IsValid) { //try //{ // await sqlBreakerPolicy.ExecuteAsync(async () => // { _db.UserInfo.Add(userInfo); await _db.SaveChangesAsync(); // }); //} //catch (Exception ex) //{ // _logger.LogError(ex.ToString()); // return BadRequest(ex.ToString()); //} } try { response = await _notificationClient.SendNotification(userInfo.EmailAddress); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(BadRequest(ex.ToString())); } if (response.IsSuccessStatusCode) { string confirmation = await response.Content.ReadAsStringAsync(); if (confirmation.Contains("http://notification")) { return(BadRequest("Docker Service is down")); } return(Ok(confirmation)); } } catch (Exception ex) { if (ex.ToString().Contains("The circuit is now open")) { //Return default value on exception. _logger.LogError(ex.ToString()); return(BadRequest("Circuit Breaker Policy Invoke to Open State.")); } else if (ex.ToString().Contains("Polly.Bulkhead.BulkheadRejectedException")) { _logger.LogError(ex.ToString()); return(BadRequest("Bulkhead Isolation Policy Invoked.")); } else { _logger.LogError(ex.ToString()); return(BadRequest(ex.ToString())); } } _logger.LogError("Unknown Exception Occurred."); return(BadRequest("Unknown Exception Occurred.")); }