Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ec62f5a566 | |||
| a23953fe11 | |||
| 6ac6b1e08e | |||
| b4a9d797dd | |||
| eba39f8c5a | |||
| 3a217bc28e | |||
| 0df3605c40 |
@@ -59,7 +59,7 @@ namespace PortBlog.API.Controllers
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogCritical(ex, "Exception while sending OTP for {ToEmail}.", messageSendDto.ToEmail);
|
logger.LogCritical(ex, "Exception while sending OTP for {ToEmail}.", messageSendDto.ToEmail);
|
||||||
return StatusCode(500, ex.Message);
|
return StatusCode(500, "A problem happened while handling your request.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -262,8 +262,8 @@ namespace PortBlog.API.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogCritical(ex, "Exception while sending message from {Name}.", message.Name);
|
_logger.LogCritical($"Exception while sending message from {message.Name}.", ex);
|
||||||
return StatusCode(500, ex.Message);
|
return StatusCode(500, "A problem happened while handling your request.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-15
@@ -33,26 +33,14 @@ Log.Logger = loggerConfiguration
|
|||||||
.WriteTo.File("logs/portblog.txt", rollingInterval: RollingInterval.Day)
|
.WriteTo.File("logs/portblog.txt", rollingInterval: RollingInterval.Day)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
|
|
||||||
var urlsSection = builder.Configuration.GetSection("Urls");
|
var urls = builder.Configuration.GetSection("Urls");
|
||||||
var urlsValue = urlsSection.Value;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(urlsValue))
|
if (!string.IsNullOrEmpty(urls.Value))
|
||||||
{
|
{
|
||||||
var allowedUrlsToUse = urlsValue
|
var allowedUrlsToUse = urls.Value.Split(',');
|
||||||
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
|
||||||
.Where(u => Uri.IsWellFormedUriString(u, UriKind.Absolute))
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
if (allowedUrlsToUse.Length > 0)
|
|
||||||
{
|
|
||||||
builder.WebHost.UseUrls(allowedUrlsToUse);
|
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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var allowedCorsOrigins = builder.Configuration.GetSection("AllowedCorsOrigins");
|
var allowedCorsOrigins = builder.Configuration.GetSection("AllowedCorsOrigins");
|
||||||
string[] origins = [];
|
string[] origins = [];
|
||||||
|
|||||||
@@ -67,14 +67,16 @@ namespace PortBlog.API.Services
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Log full exception and persist failed message.
|
logger.LogCritical(
|
||||||
logger.LogCritical(ex, "Exception while sending mail from {FromEmail} ({Name}).", messageSendDto.FromEmail, messageSendDto.Name);
|
"Exception while sending mail from {FromEmail} ({Name}): {Exception}",
|
||||||
|
messageSendDto.FromEmail,
|
||||||
|
messageSendDto.Name,
|
||||||
|
ex.Message
|
||||||
|
);
|
||||||
messageSendDto.SentStatus = (int)MailConstants.MailStatus.Failed;
|
messageSendDto.SentStatus = (int)MailConstants.MailStatus.Failed;
|
||||||
mailRepository.AddMessage(messageEntity);
|
mailRepository.AddMessage(messageEntity);
|
||||||
await mailRepository.SaveChangesAsync();
|
await mailRepository.SaveChangesAsync();
|
||||||
|
throw new Exception();
|
||||||
// Throw a descriptive exception so callers can return an error message to the client.
|
|
||||||
throw new InvalidOperationException($"Failed to send email to '{messageSendDto.ToEmail}'. See inner exception for details.", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user