From cef098f26566ba521c51a06a4a5fe1ea87e9a031 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 1 Jul 2024 15:50:48 +0200 Subject: [PATCH] =?UTF-8?q?Try-Catch=20zum=20GroupOfUserController=20hinzu?= =?UTF-8?q?gef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GroupOfUserController.cs | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs b/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs index 6f658ac..9673b1d 100644 --- a/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs +++ b/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs @@ -18,13 +18,21 @@ namespace DigitalData.UserManager.API.Controllers [HttpDelete] public async Task Delete([FromQuery] int groupId, [FromQuery] int userId) { - var result = await _service.DeleteAsyncByGroupUserId(groupId, userId); - if (result.IsSuccess) + try { - return Ok(result); - } + var result = await _service.DeleteAsyncByGroupUserId(groupId, userId); + if (result.IsSuccess) + { + return Ok(result); + } - return BadRequest(result); + return BadRequest(result); + } + catch (Exception ex) + { + _logger.LogError(ex, "{Message}", ex.Message); + return StatusCode(StatusCodes.Status500InternalServerError); + } } [NonAction] @@ -33,19 +41,35 @@ namespace DigitalData.UserManager.API.Controllers [HttpGet] public async Task GetAll([FromQuery]bool withUser = false, [FromQuery]bool withGroup = false) { - var result = await _service.ReadAllAsyncWith(withUser, withGroup); - if (result.IsSuccess) + try { - return Ok(result); - } + var result = await _service.ReadAllAsyncWith(withUser, withGroup); + if (result.IsSuccess) + { + return Ok(result); + } - return NotFound(result); + return NotFound(result); + } + catch(Exception ex) + { + _logger.LogError(ex, "{Message}", ex.Message); + return StatusCode(StatusCodes.Status500InternalServerError); + } } [HttpGet("Has")] public async Task HasGroup([FromQuery] string username, [FromQuery] string groupname) { - return Ok(await _service.HasGroup(username, groupname)); + try + { + return Ok(await _service.HasGroup(username, groupname)); + } + catch(Exception ex) + { + _logger.LogError(ex, "{Message}", ex.Message); + return StatusCode(StatusCodes.Status500InternalServerError); + } } } } \ No newline at end of file