mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 13:18:00 +01:00
Handle "transport not allowed" responses from the registration service
This commit is contained in:
committed by
Jon Chambers
parent
3e53884979
commit
300ac16cf1
@@ -74,6 +74,7 @@ import org.whispersystems.textsecuregcm.registration.MessageTransport;
|
||||
import org.whispersystems.textsecuregcm.registration.RegistrationServiceClient;
|
||||
import org.whispersystems.textsecuregcm.registration.RegistrationServiceException;
|
||||
import org.whispersystems.textsecuregcm.registration.RegistrationServiceSenderException;
|
||||
import org.whispersystems.textsecuregcm.registration.TransportNotAllowedException;
|
||||
import org.whispersystems.textsecuregcm.registration.VerificationSession;
|
||||
import org.whispersystems.textsecuregcm.spam.Extract;
|
||||
import org.whispersystems.textsecuregcm.spam.FilterSpam;
|
||||
@@ -488,8 +489,13 @@ public class VerificationController {
|
||||
|
||||
throw registrationServiceException.getRegistrationSession()
|
||||
.map(s -> buildResponse(s, verificationSession))
|
||||
.map(verificationSessionResponse -> new ClientErrorException(
|
||||
Response.status(Response.Status.CONFLICT).entity(verificationSessionResponse).build()))
|
||||
.map(verificationSessionResponse -> {
|
||||
final Response response = registrationServiceException instanceof TransportNotAllowedException
|
||||
? Response.status(418).entity(verificationSessionResponse).build()
|
||||
: Response.status(Response.Status.CONFLICT).entity(verificationSessionResponse).build();
|
||||
|
||||
return new ClientErrorException(response);
|
||||
})
|
||||
.orElseGet(NotFoundException::new);
|
||||
|
||||
} else if (unwrappedException instanceof RegistrationServiceSenderException) {
|
||||
|
||||
@@ -157,6 +157,8 @@ public class RegistrationServiceClient implements Managed {
|
||||
RegistrationServiceSenderException.illegalArgument(response.getError().getMayRetry()));
|
||||
case SEND_VERIFICATION_CODE_ERROR_TYPE_UNSPECIFIED -> throw new CompletionException(
|
||||
RegistrationServiceSenderException.unknown(response.getError().getMayRetry()));
|
||||
case SEND_VERIFICATION_CODE_ERROR_TYPE_TRANSPORT_NOT_ALLOWED -> throw new CompletionException(
|
||||
new TransportNotAllowedException(buildSessionResponseFromMetadata(response.getSessionMetadata())));
|
||||
|
||||
default -> throw new CompletionException(
|
||||
new RuntimeException("Failed to send verification code: " + response.getError().getErrorType()));
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.whispersystems.textsecuregcm.registration;
|
||||
|
||||
import org.whispersystems.textsecuregcm.entities.RegistrationServiceSession;
|
||||
|
||||
/**
|
||||
* Indicates that a request to send a verification code failed because the destination number does not support the
|
||||
* requested transport (e.g. the caller asked to send an SMS to a landline number).
|
||||
*/
|
||||
public class TransportNotAllowedException extends RegistrationServiceException {
|
||||
|
||||
public TransportNotAllowedException(RegistrationServiceSession registrationServiceSession) {
|
||||
super(registrationServiceSession);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user