Merge pull request 'Improve error handling and logging for mail and OTP endpoints' (#7) from feature/portfolio-admin-auth into dev
Reviewed-on: #7
This commit is contained in:
commit
62fc6c1a49
@ -59,7 +59,7 @@ namespace PortBlog.API.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
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)
|
||||
{
|
||||
_logger.LogCritical($"Exception while sending message from {message.Name}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
_logger.LogCritical(ex, "Exception while sending message from {Name}.", message.Name);
|
||||
return StatusCode(500, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,14 +67,14 @@ 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
|
||||
// Log full exception and persist failed message.
|
||||
logger.LogCritical(ex, "Exception while sending mail from {FromEmail} ({Name}).", messageSendDto.FromEmail, messageSendDto.Name);
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user