Send an HTTP/440 response instead of an HTTP/502 if an upstream provider rejects a "send verification code" request

This commit is contained in:
Jon Chambers 2023-08-02 14:33:28 -04:00 committed by Jon Chambers
parent 43fd8518c0
commit 5c31ef43c9
2 changed files with 4 additions and 2 deletions

View File

@ -12,9 +12,11 @@ import org.whispersystems.textsecuregcm.registration.RegistrationServiceSenderEx
public class RegistrationServiceSenderExceptionMapper implements ExceptionMapper<RegistrationServiceSenderException> { public class RegistrationServiceSenderExceptionMapper implements ExceptionMapper<RegistrationServiceSenderException> {
public static int REMOTE_SERVICE_REJECTED_REQUEST_STATUS = 440;
@Override @Override
public Response toResponse(final RegistrationServiceSenderException exception) { public Response toResponse(final RegistrationServiceSenderException exception) {
return Response.status(Response.Status.BAD_GATEWAY) return Response.status(REMOTE_SERVICE_REJECTED_REQUEST_STATUS)
.entity(new SendVerificationCodeFailureResponse(exception.getReason(), exception.isPermanent())) .entity(new SendVerificationCodeFailureResponse(exception.getReason(), exception.isPermanent()))
.build(); .build();
} }

View File

@ -1071,7 +1071,7 @@ class VerificationControllerTest {
.request() .request()
.header(HttpHeaders.X_FORWARDED_FOR, "127.0.0.1"); .header(HttpHeaders.X_FORWARDED_FOR, "127.0.0.1");
try (Response response = request.post(Entity.json(requestVerificationCodeJson("voice", "ios")))) { try (Response response = request.post(Entity.json(requestVerificationCodeJson("voice", "ios")))) {
assertEquals(HttpStatus.SC_BAD_GATEWAY, response.getStatus()); assertEquals(RegistrationServiceSenderExceptionMapper.REMOTE_SERVICE_REJECTED_REQUEST_STATUS, response.getStatus());
final Map<String, Object> responseMap = response.readEntity(Map.class); final Map<String, Object> responseMap = response.readEntity(Map.class);