Compare commits

..

No commits in common. "4ab4c615e9d469593bcf7023049cf55f8918b8bf" and "ec62f5a5667b011046440b7ece8a9aab2adc17b9" have entirely different histories.

2 changed files with 11 additions and 21 deletions

View File

@ -33,25 +33,13 @@ Log.Logger = loggerConfiguration
.WriteTo.File("logs/portblog.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
var urlsSection = builder.Configuration.GetSection("Urls");
var urlsValue = urlsSection.Value;
var urls = builder.Configuration.GetSection("Urls");
if (!string.IsNullOrWhiteSpace(urlsValue))
if (!string.IsNullOrEmpty(urls.Value))
{
var allowedUrlsToUse = urlsValue
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Where(u => Uri.IsWellFormedUriString(u, UriKind.Absolute))
.ToArray();
var allowedUrlsToUse = urls.Value.Split(',');
if (allowedUrlsToUse.Length > 0)
{
builder.WebHost.UseUrls(allowedUrlsToUse);
}
else
{
// optionally log or throw depending on desired behavior
Log.Warning("Configured 'Urls' section was present but no valid URLs were found.");
}
builder.WebHost.UseUrls(allowedUrlsToUse);
}
var allowedCorsOrigins = builder.Configuration.GetSection("AllowedCorsOrigins");

View File

@ -67,14 +67,16 @@ namespace PortBlog.API.Services
}
catch (Exception ex)
{
// Log full exception and persist failed message. Do not rethrow to avoid causing a 500 from OTP generation
logger.LogCritical(ex, "Exception while sending mail from {FromEmail} ({Name}).", messageSendDto.FromEmail, messageSendDto.Name);
logger.LogCritical(
"Exception while sending mail from {FromEmail} ({Name}): {Exception}",
messageSendDto.FromEmail,
messageSendDto.Name,
ex.Message
);
messageSendDto.SentStatus = (int)MailConstants.MailStatus.Failed;
mailRepository.AddMessage(messageEntity);
await mailRepository.SaveChangesAsync();
// swallow the exception so OTP generation continues; caller can inspect delivery status via message logs
return;
throw new Exception();
}
}
}