public async Task <IActionResult> Get(string id) { try { if (!HttpContext.Request.IsHttps)//if request is not https, then throw unauthorized exception { throw new UnauthorizedAccessException("Request must be HTTPS"); } Guid entityId = new Guid(id); var existingCredential = repository.GetOne(entityId); if (existingCredential == null) { return(NotFound()); } if (_credentialManager.ValidateRetrievalDate(existingCredential)) { existingCredential.PasswordSecret = _credentialManager.GetPassword(existingCredential); return(Ok(existingCredential)); } ModelState.AddModelError("Credential", "Current date does not fall withing the start and end date range"); return(BadRequest(ModelState)); } catch (Exception ex) { return(ex.GetActionResult()); } }