Benutzerdefinierte Fehlerseiten für die Statuscodes 404 und 500 im HomeController hinzugefügt, um verschiedene Benutzerfälle zu behandeln.

This commit is contained in:
Developer 02
2024-04-26 12:22:09 +02:00
parent 966b7de3c4
commit 6b3c90c618
13 changed files with 137 additions and 51 deletions

View File

@@ -19,5 +19,7 @@ namespace EnvelopeGenerator.Application.Contracts
Task<IServiceResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode);
Task<IServiceResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode);
Task<IServiceResult<bool>> IsExisting(string envelopeReceiverId);
}
}

View File

@@ -2,6 +2,7 @@
{
public enum EnvelopeFlag
{
EnvelopeOrReceiverNonexists
EnvelopeOrReceiverNonexists,
NonDecodableEnvelopeReceiverId
}
}

View File

@@ -6,19 +6,20 @@ namespace EnvelopeGenerator.Application
{
public static class EnvelopeGeneratorExtensions
{
public static void LogEnvelopeError(this ILogger logger, string receiverId, string? message, params object?[] args)
public static void LogEnvelopeError(this ILogger logger, string envelopeEeceiverId, Exception? exception = null, string? message = null, params object?[] args)
{
(string? envelopeUuid, string? receiverSignature) = receiverId.DecodeEnvelopeReceiverId();
var sb = new StringBuilder($"Envelope Uuid: {envelopeUuid}\nReceiver Signature: {receiverSignature}");
var sb = new StringBuilder(envelopeEeceiverId.DecodeEnvelopeReceiverId().ToTitle());
if (message is not null)
sb.AppendLine().Append(message);
logger.Log(LogLevel.Error, sb.ToString(), args);
if(exception is null)
logger.Log(LogLevel.Error, sb.ToString(), args);
else
logger.Log(LogLevel.Error, exception, sb.ToString(), args);
}
public static void LogEnvelopeError(this ILogger logger, string uuid, string? signature = null, string? message = null, params object?[] args)
public static void LogEnvelopeError(this ILogger logger, string? uuid, string? signature = null, Exception? exception = null, string? message = null, params object?[] args)
{
var sb = new StringBuilder($"Envelope Uuid: {uuid}");
@@ -28,7 +29,10 @@ namespace EnvelopeGenerator.Application
if (message is not null)
sb.AppendLine().Append(message);
logger.Log(LogLevel.Error, sb.ToString(), args);
if (exception is null)
logger.Log(LogLevel.Error, sb.ToString(), args);
else
logger.Log(LogLevel.Error, exception, sb.ToString(), args);
}
public static string ToTitle(this (string? UUID, string? Signature) envelopeReceiverTuple)

View File

@@ -95,5 +95,16 @@ namespace EnvelopeGenerator.Application.Services
return await VerifyAccessCodeAsync(uuid: uuid, signature: signature, accessCode: accessCode);
}
public async Task<IServiceResult<bool>> IsExisting(string envelopeReceiverId)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
if (uuid is null || signature is null)
return Failed(false).WithFlag(EnvelopeFlag.NonDecodableEnvelopeReceiverId);
int count = await _repository.CountAsync(uuid:uuid, signature:signature);
return Successful(count > 0);
}
}
}