Ajout de try catch pour une meilleure gestion d'erreurs.
This commit is contained in:
@@ -30,12 +30,6 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
if (artiste == null)
|
||||
{
|
||||
this._logger.LogError("L'artiste à ajouter ne peut pas être null.");
|
||||
throw new ArgumentNullException(nameof(artiste));
|
||||
}
|
||||
|
||||
if (this._artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
|
||||
{
|
||||
this._logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
|
||||
@@ -70,23 +64,32 @@
|
||||
/// <inheritdoc/>
|
||||
public Artiste Find(int id)
|
||||
{
|
||||
Artiste artiste = this._artistes.FirstOrDefault(a => a.IdArtiste == id);
|
||||
if (artiste == null)
|
||||
try
|
||||
{
|
||||
this._logger.LogWarning("Aucun artiste trouvé avec l'identifiant {Id}", id);
|
||||
Artiste artiste = this._artistes.First(a => a.IdArtiste == id);
|
||||
return artiste;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec ID: {Id}", id);
|
||||
throw;
|
||||
}
|
||||
return artiste;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Artiste FindByName(string nom)
|
||||
{
|
||||
Artiste artiste = this._artistes.FirstOrDefault(a => a.Nom == nom);
|
||||
if (artiste == null)
|
||||
try
|
||||
{
|
||||
this._logger.LogWarning("Aucun artiste trouvé avec le nom {Nom}", nom);
|
||||
Artiste artiste = this._artistes.First(a => a.Nom == nom);
|
||||
return artiste;
|
||||
}
|
||||
return artiste;
|
||||
catch (Exception ex)
|
||||
{
|
||||
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -99,12 +102,6 @@
|
||||
/// <inheritdoc/>
|
||||
public void Update(Artiste artiste)
|
||||
{
|
||||
if (artiste == null)
|
||||
{
|
||||
this._logger.LogError("L'artiste à mettre à jour ne peut pas être null.");
|
||||
throw new ArgumentNullException(nameof(artiste));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var artisteToUpdate = this._artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
|
||||
|
||||
Reference in New Issue
Block a user