Created
February 2, 2021 16:29
-
-
Save SibeeshVenu/03faa0fc5efeea32d00732192db882bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet("getusers")] | |
public async Task<IActionResult> GetUsers() | |
{ | |
try | |
{ | |
_logger.LogInformation($"The method {nameof(GetUsers)} is called"); | |
var users = await _adminService.GetUserList(HttpContext.GetSelectedTenantId()); | |
if (!users.Any()) | |
{ | |
_logger.LogCritical($"The method {nameof(GetUsers)} returned no users"); | |
return new NoContentResult(); | |
} | |
return new OkObjectResult(users); | |
} | |
catch (MsalException ex) | |
{ | |
HttpContext.Response.ContentType = "application/json"; | |
HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; | |
_logger.LogError($"An authentication error occurred while acquiring a token for downstream API. Error message: { ex.Message}"); | |
return new UnauthorizedObjectResult($"An authentication error occurred while acquiring a token for downstream API. Error message: { ex.Message}"); | |
} | |
catch (AdminException ex) | |
{ | |
return new BadRequestObjectResult(ex.ToErrorResult()); | |
} | |
catch (Exception ex) | |
{ | |
if (ex.InnerException is MicrosoftIdentityWebChallengeUserException challengeException) | |
{ | |
_logger.LogError($"Interaction required. Error message: { challengeException}"); | |
return new BadRequestObjectResult($"Interaction required. Error message: { challengeException}"); | |
} | |
else | |
{ | |
_logger.LogError(ex.Message); | |
return new StatusCodeResult(500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment