commit
3d4fa16d04
@ -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, "A problem happened while handling your request.");
|
return StatusCode(500, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -262,8 +262,8 @@ namespace PortBlog.API.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogCritical($"Exception while sending message from {message.Name}.", ex);
|
_logger.LogCritical(ex, "Exception while sending message from {Name}.", message.Name);
|
||||||
return StatusCode(500, "A problem happened while handling your request.");
|
return StatusCode(500, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,14 +67,14 @@ namespace PortBlog.API.Services
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Log full exception and persist failed message. Do not rethrow to avoid causing a 500 from OTP generation
|
// Log full exception and persist failed message.
|
||||||
logger.LogCritical(ex, "Exception while sending mail from {FromEmail} ({Name}).", messageSendDto.FromEmail, messageSendDto.Name);
|
logger.LogCritical(ex, "Exception while sending mail from {FromEmail} ({Name}).", messageSendDto.FromEmail, messageSendDto.Name);
|
||||||
messageSendDto.SentStatus = (int)MailConstants.MailStatus.Failed;
|
messageSendDto.SentStatus = (int)MailConstants.MailStatus.Failed;
|
||||||
mailRepository.AddMessage(messageEntity);
|
mailRepository.AddMessage(messageEntity);
|
||||||
await mailRepository.SaveChangesAsync();
|
await mailRepository.SaveChangesAsync();
|
||||||
|
|
||||||
// swallow the exception so OTP generation continues; caller can inspect delivery status via message logs
|
// Throw a descriptive exception so callers can return an error message to the client.
|
||||||
return;
|
throw new InvalidOperationException($"Failed to send email to '{messageSendDto.ToEmail}'. See inner exception for details.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user