#199 : Test de correction pour postgre.
This commit is contained in:
@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
/// <summary>
|
||||
/// Filtre d'exception global qui intercepte toute exception non gérée et la journalise automatiquement.
|
||||
/// Filtre d'exception global qui intercepte toute exception non geree et la journalise automatiquement.
|
||||
/// </summary>
|
||||
public class GlobalExceptionFilter : IExceptionFilter
|
||||
{
|
||||
@@ -13,7 +13,7 @@ public class GlobalExceptionFilter : IExceptionFilter
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GlobalExceptionFilter"/> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
/// <param name="logger">Service de journalisation injecte.</param>
|
||||
public GlobalExceptionFilter(ILogger<GlobalExceptionFilter> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -22,11 +22,14 @@ public class GlobalExceptionFilter : IExceptionFilter
|
||||
/// <inheritdoc/>
|
||||
public void OnException(ExceptionContext context)
|
||||
{
|
||||
string detail = BuildExceptionDetail(context.Exception);
|
||||
|
||||
this.logger.LogError(
|
||||
context.Exception,
|
||||
"Erreur non gérée dans {Action} : {Message}",
|
||||
"Erreur non geree dans {Action} : {Message} | Details: {Details}",
|
||||
context.ActionDescriptor.DisplayName,
|
||||
context.Exception.Message);
|
||||
context.Exception.Message,
|
||||
detail);
|
||||
|
||||
context.Result = new ObjectResult(new
|
||||
{
|
||||
@@ -39,4 +42,18 @@ public class GlobalExceptionFilter : IExceptionFilter
|
||||
|
||||
context.ExceptionHandled = true;
|
||||
}
|
||||
|
||||
private static string BuildExceptionDetail(Exception exception)
|
||||
{
|
||||
var messages = new List<string>();
|
||||
Exception? current = exception;
|
||||
|
||||
while (current != null)
|
||||
{
|
||||
messages.Add($"{current.GetType().Name}: {current.Message}");
|
||||
current = current.InnerException;
|
||||
}
|
||||
|
||||
return string.Join(" --> ", messages);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user