mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-03 15:03:29 +00:00
28 lines
821 B
C#
28 lines
821 B
C#
|
|
using System.Globalization;
|
||
|
|
using System.Runtime.CompilerServices;
|
||
|
|
using Microsoft.Extensions.Logging;
|
||
|
|
|
||
|
|
namespace Api.SeaHavenIndustries.Helper;
|
||
|
|
|
||
|
|
internal static class SanitizedErrors
|
||
|
|
{
|
||
|
|
private const string DefaultPublicMessage = "An unexpected error occurred";
|
||
|
|
|
||
|
|
public static string Sanitize(
|
||
|
|
this ILogger logger,
|
||
|
|
Exception exception,
|
||
|
|
string? publicMessage = null,
|
||
|
|
[CallerMemberName] string operation = "")
|
||
|
|
{
|
||
|
|
var correlationId = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
|
||
|
|
|
||
|
|
logger.LogError(
|
||
|
|
exception,
|
||
|
|
"Unhandled exception in {Operation}. CorrelationId: {CorrelationId}",
|
||
|
|
operation,
|
||
|
|
correlationId);
|
||
|
|
|
||
|
|
return $"{publicMessage ?? DefaultPublicMessage} (reference {correlationId}).";
|
||
|
|
}
|
||
|
|
}
|