Include country code for verify failure
This commit is contained in:
parent
50f5d760c9
commit
628a112b38
|
@ -133,7 +133,8 @@ public class TwilioSmsSender {
|
||||||
smsMeter.mark();
|
smsMeter.mark();
|
||||||
|
|
||||||
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||||
.thenApply(this::parseResponse).handle(this::processResponse);
|
.thenApply(this::parseResponse)
|
||||||
|
.handle((response, throwable) -> processResponse(response, throwable, destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getBodyFormatString(@Nonnull String destination, @Nullable String clientType) {
|
private String getBodyFormatString(@Nonnull String destination, @Nullable String clientType) {
|
||||||
|
@ -199,25 +200,28 @@ public class TwilioSmsSender {
|
||||||
|
|
||||||
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||||
.thenApply(this::parseResponse)
|
.thenApply(this::parseResponse)
|
||||||
.handle(this::processResponse);
|
.handle((response, throwable) -> processResponse(response, throwable, destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRandom(Random random, List<String> elements) {
|
private String getRandom(Random random, List<String> elements) {
|
||||||
return elements.get(random.nextInt(elements.size()));
|
return elements.get(random.nextInt(elements.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processResponse(TwilioResponse response, Throwable throwable) {
|
private boolean processResponse(TwilioResponse response, Throwable throwable, String destination) {
|
||||||
if (response != null && response.isSuccess()) {
|
if (response != null && response.isSuccess()) {
|
||||||
priceMeter.mark((long) (response.successResponse.price * 1000));
|
priceMeter.mark((long) (response.successResponse.price * 1000));
|
||||||
return true;
|
return true;
|
||||||
} else if (response != null && response.isFailure()) {
|
} else if (response != null && response.isFailure()) {
|
||||||
logger.debug("Twilio request failed: " + response.failureResponse.status + "(code " + response.failureResponse.code + "), " + response.failureResponse.message);
|
|
||||||
|
|
||||||
Metrics.counter(FAILED_REQUEST_COUNTER_NAME,
|
Metrics.counter(FAILED_REQUEST_COUNTER_NAME,
|
||||||
SERVICE_NAME_TAG, "classic",
|
SERVICE_NAME_TAG, "classic",
|
||||||
STATUS_CODE_TAG_NAME, String.valueOf(response.failureResponse.status),
|
STATUS_CODE_TAG_NAME, String.valueOf(response.failureResponse.status),
|
||||||
ERROR_CODE_TAG_NAME, String.valueOf(response.failureResponse.code)).increment();
|
ERROR_CODE_TAG_NAME, String.valueOf(response.failureResponse.code)).increment();
|
||||||
|
|
||||||
|
logger.info("Failed with code={}, country={}",
|
||||||
|
response.failureResponse.code,
|
||||||
|
Util.getCountryCode(destination));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} else if (throwable != null) {
|
} else if (throwable != null) {
|
||||||
logger.info("Twilio request failed", throwable);
|
logger.info("Twilio request failed", throwable);
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -113,7 +112,7 @@ class TwilioVerifySender {
|
||||||
|
|
||||||
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||||
.thenApply(this::parseResponse)
|
.thenApply(this::parseResponse)
|
||||||
.handle(this::extractVerifySid);
|
.handle((response, throwable) -> extractVerifySid(response, throwable, destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<String> findBestLocale(List<LanguageRange> priorityList) {
|
private Optional<String> findBestLocale(List<LanguageRange> priorityList) {
|
||||||
|
@ -138,18 +137,19 @@ class TwilioVerifySender {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<Optional<String>> deliverVoxVerificationWithVerify(String destination, String verificationCode,
|
CompletableFuture<Optional<String>> deliverVoxVerificationWithVerify(String destination,
|
||||||
List<LanguageRange> languageRanges) {
|
String verificationCode, List<LanguageRange> languageRanges) {
|
||||||
|
|
||||||
HttpRequest request = buildVerifyRequest("call", destination, verificationCode, findBestLocale(languageRanges),
|
HttpRequest request = buildVerifyRequest("call", destination, verificationCode, findBestLocale(languageRanges),
|
||||||
Optional.empty());
|
Optional.empty());
|
||||||
|
|
||||||
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||||
.thenApply(this::parseResponse)
|
.thenApply(this::parseResponse)
|
||||||
.handle(this::extractVerifySid);
|
.handle((response, throwable) -> extractVerifySid(response, throwable, destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<String> extractVerifySid(TwilioVerifyResponse twilioVerifyResponse, Throwable throwable) {
|
private Optional<String> extractVerifySid(TwilioVerifyResponse twilioVerifyResponse, Throwable throwable,
|
||||||
|
String destination) {
|
||||||
|
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
logger.warn("Failed to send Twilio request", throwable);
|
logger.warn("Failed to send Twilio request", throwable);
|
||||||
|
@ -162,6 +162,10 @@ class TwilioVerifySender {
|
||||||
TwilioSmsSender.STATUS_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.status),
|
TwilioSmsSender.STATUS_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.status),
|
||||||
TwilioSmsSender.ERROR_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.code)).increment();
|
TwilioSmsSender.ERROR_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.code)).increment();
|
||||||
|
|
||||||
|
logger.info("Failed with code={}, country={}",
|
||||||
|
twilioVerifyResponse.failureResponse.code,
|
||||||
|
Util.getCountryCode(destination));
|
||||||
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue