Skip to content

Commit

Permalink
Added error cases for email failure
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Nov 15, 2022
1 parent 0eb5cb1 commit 80d5772
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ private boolean sendOtpByEmailOrSms(AuthenticationFlowContext context, String mo
case Constants.EMAIL:
retValue = sendEmailViaSunbird(context, mobileNumber, otp);
break;
default:
logger.error("Failed to identify given key is email or mobile.");
break;
}
logger.info("SMS for OTP send successfully ? " + retValue);
logger.info("Email/SMS for OTP send successfully ? " + retValue);
return retValue;
}

Expand Down Expand Up @@ -367,13 +370,22 @@ private boolean sendEmailViaSunbird(AuthenticationFlowContext context, String us
Map<String, Object> request = new HashMap<>();
request.put(Constants.REQUEST, otpResponse);

HttpResponse response = HttpClient.post(request,
(System.getenv(Constants.SUNBIRD_LMS_BASE_URL) + Constants.SEND_NOTIFICATION_URI),
System.getenv(Constants.SUNBIRD_LMS_AUTHORIZATION));

int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
return true;
HttpResponse response = null;
try {
response = HttpClient.post(request,
(System.getenv(Constants.SUNBIRD_LMS_BASE_URL) + Constants.SEND_NOTIFICATION_URI),
System.getenv(Constants.SUNBIRD_LMS_AUTHORIZATION));
if (response.getStatusLine() != null) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
return true;
} else {
logger.error(
String.format("Failed to send email for OTP Login. Received StatusCode: %s", statusCode));
}
}
} catch (Exception e) {
logger.error("Failed to send Email Notification for OTP Login. Exception: ", e);
}
return false;
}
Expand Down

0 comments on commit 80d5772

Please sign in to comment.