refactor(GroupController): remove try-catch block

This commit is contained in:
Developer 02 2025-08-05 19:47:56 +02:00
parent 9fd66d41ca
commit d252859b11

View File

@ -18,26 +18,18 @@ public class GroupController : BaseAuthController<IGroupService, GroupCreateDto,
[HttpPost("ByDir")]
public async Task<IActionResult> CreateByDir(DirectoryGroupDto adGroup)
{
try
{
return await _service.CreateAsync(adGroup).ThenAsync(
Success: id =>
{
var createdResource = new { Id = id };
var actionName = nameof(GetById);
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
},
Fail: IActionResult (m, n) =>
{
_logger.LogNotice(n);
return BadRequest();
});
}
catch (Exception ex)
{
_logger.LogError(ex, "{Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
return await _service.CreateAsync(adGroup).ThenAsync(
Success: id =>
{
var createdResource = new { Id = id };
var actionName = nameof(GetById);
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
},
Fail: IActionResult (m, n) =>
{
_logger.LogNotice(n);
return BadRequest();
});
}
}