From 4725614bb3d8ebac4dfe73d923e2e3ace504c832 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 5 Aug 2025 19:45:37 +0200 Subject: [PATCH] refactor(AuthController): remove try-catch block --- .../Controllers/AuthController.cs | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/DigitalData.UserManager.API/Controllers/AuthController.cs b/src/DigitalData.UserManager.API/Controllers/AuthController.cs index b469a4f..98048c2 100644 --- a/src/DigitalData.UserManager.API/Controllers/AuthController.cs +++ b/src/DigitalData.UserManager.API/Controllers/AuthController.cs @@ -40,26 +40,18 @@ public class AuthController : ControllerBase [Obsolete("Use MediatR")] public async Task GetUserWithClaims() { - try - { - // Extract the username from the Name claim. - string? username = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value; + // Extract the username from the Name claim. + string? username = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value; - if (string.IsNullOrEmpty(username)) - return Unauthorized(); + if (string.IsNullOrEmpty(username)) + return Unauthorized(); - return await _userService.ReadByUsernameAsync(username) - .ThenAsync(Ok, IActionResult (m, n) => - { - _logger.LogNotice(n); - return NotFound(Result.Fail().Message(_localizer[Key.UserNotFound])); - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "{Message}", ex.Message); - return StatusCode(StatusCodes.Status500InternalServerError); - } + return await _userService.ReadByUsernameAsync(username) + .ThenAsync(Ok, IActionResult (m, n) => + { + _logger.LogNotice(n); + return NotFound(Result.Fail().Message(_localizer[Key.UserNotFound])); + }); } [Authorize]