ajout d'un exception personnalisée

crud/security
Victor GABORIT 1 year ago
parent b1420b5600
commit 384ae84ca1

@ -26,6 +26,7 @@
<ItemGroup>
<ProjectReference Include="..\ModelToEntity\ModelToEntity.csproj" />
<ProjectReference Include="..\Services\Services.csproj" />
<ProjectReference Include="..\Utils\Utils.csproj" />
</ItemGroup>
</Project>

@ -8,6 +8,7 @@ using Model.Business;
using Model.DTO;
using Model.Mappers;
using Services;
using Utils;
namespace API.Controllers
{
@ -46,7 +47,7 @@ namespace API.Controllers
_logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
return Ok(await _dataService.UserService.GetItems(1, 1, UserProperty.Id.ToString(), id));
}
catch (InvalidOperationException)
catch (NoDataFoundException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
@ -61,7 +62,7 @@ namespace API.Controllers
_logger.LogInformation("[INFORMATION] Utilisateur avec le username {username} a été trouvé.", username);
return Ok(await _dataService.UserService.GetItems(1, 1, UserProperty.Username.ToString(), username));
}
catch (InvalidOperationException)
catch (NoDataFoundException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec le username {username}.", username);
return NotFound();

@ -17,9 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelToEntity", "ModelToEntity\ModelToEntity.csproj", "{8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{B28FD539-6FE4-4B13-9C1F-D88F4771CC69}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{2E7CADAB-30EA-4B9C-922B-EBD08E03686E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -55,14 +57,18 @@ Global
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.Build.0 = Release|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.Build.0 = Release|Any CPU
{8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Release|Any CPU.Build.0 = Release|Any CPU
{B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Release|Any CPU.Build.0 = Release|Any CPU
{2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -25,6 +25,7 @@
<ProjectReference Include="..\ModelToEntity\ModelToEntity.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\Utils\Utils.csproj" />
</ItemGroup>
</Project>

@ -10,6 +10,7 @@ using Model.Business;
using Microsoft.EntityFrameworkCore;
using Entities.SQLudeoDB;
using ModelToEntity;
using Utils;
namespace Services
{
@ -83,7 +84,7 @@ namespace Services
var items = await dataServiceEF.GetItems(page, count, orderingPropertyName, valueProperty);
if (items == null)
{
throw new InvalidOperationException("aucune donnée trouvé");
throw new NoDataFoundException();
}
return items.Select(item => item.FromModelToDTO());
}

Loading…
Cancel
Save