Search in sources :

Example 1 with LockedException

use of org.whispersystems.signalservice.internal.push.LockedException in project Signal-Android by WhisperSystems.

the class DefaultErrorMapper method parseError.

@Override
public Throwable parseError(int status, String body, Function<String, String> getHeader) {
    if (customErrorMappers.containsKey(status)) {
        try {
            return customErrorMappers.get(status).parseError(status, body, getHeader);
        } catch (MalformedResponseException e) {
            return e;
        }
    }
    switch(status) {
        case 401:
        case 403:
            return new AuthorizationFailedException(status, "Authorization failed!");
        case 402:
            return new CaptchaRequiredException();
        case 404:
            return new NotFoundException("Not found");
        case 409:
            try {
                return new MismatchedDevicesException(JsonUtil.fromJsonResponse(body, MismatchedDevices.class));
            } catch (MalformedResponseException e) {
                return e;
            }
        case 410:
            try {
                return new StaleDevicesException(JsonUtil.fromJsonResponse(body, StaleDevices.class));
            } catch (MalformedResponseException e) {
                return e;
            }
        case 411:
            try {
                return new DeviceLimitExceededException(JsonUtil.fromJsonResponse(body, DeviceLimit.class));
            } catch (MalformedResponseException e) {
                return e;
            }
        case 413:
            return new RateLimitException("Rate limit exceeded: " + status);
        case 417:
            return new ExpectationFailedException();
        case 423:
            PushServiceSocket.RegistrationLockFailure accountLockFailure;
            try {
                accountLockFailure = JsonUtil.fromJsonResponse(body, PushServiceSocket.RegistrationLockFailure.class);
            } catch (MalformedResponseException e) {
                return e;
            }
            AuthCredentials credentials = accountLockFailure.backupCredentials;
            String basicStorageCredentials = credentials != null ? credentials.asBasic() : null;
            return new LockedException(accountLockFailure.length, accountLockFailure.timeRemaining, basicStorageCredentials);
        case 428:
            ProofRequiredResponse proofRequiredResponse;
            try {
                proofRequiredResponse = JsonUtil.fromJsonResponse(body, ProofRequiredResponse.class);
            } catch (MalformedResponseException e) {
                return e;
            }
            String retryAfterRaw = getHeader.apply("Retry-After");
            long retryAfter = Util.parseInt(retryAfterRaw, -1);
            return new ProofRequiredException(proofRequiredResponse, retryAfter);
        case 499:
            return new DeprecatedVersionException();
        case 508:
            return new ServerRejectedException();
    }
    if (status != 200 && status != 202 && status != 204) {
        return new NonSuccessfulResponseCodeException(status, "Bad response: " + status);
    }
    return null;
}
Also used : LockedException(org.whispersystems.signalservice.internal.push.LockedException) RateLimitException(org.whispersystems.signalservice.api.push.exceptions.RateLimitException) DeprecatedVersionException(org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException) ExpectationFailedException(org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException) DeviceLimit(org.whispersystems.signalservice.internal.push.DeviceLimit) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) StaleDevicesException(org.whispersystems.signalservice.internal.push.exceptions.StaleDevicesException) ProofRequiredException(org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException) MismatchedDevices(org.whispersystems.signalservice.internal.push.MismatchedDevices) StaleDevices(org.whispersystems.signalservice.internal.push.StaleDevices) DeviceLimitExceededException(org.whispersystems.signalservice.internal.push.DeviceLimitExceededException) AuthCredentials(org.whispersystems.signalservice.internal.push.AuthCredentials) AuthorizationFailedException(org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException) MismatchedDevicesException(org.whispersystems.signalservice.internal.push.exceptions.MismatchedDevicesException) PushServiceSocket(org.whispersystems.signalservice.internal.push.PushServiceSocket) CaptchaRequiredException(org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException) ProofRequiredResponse(org.whispersystems.signalservice.internal.push.ProofRequiredResponse)

Example 2 with LockedException

use of org.whispersystems.signalservice.internal.push.LockedException in project Signal-Android by WhisperSystems.

the class BaseEnterSmsCodeFragment method setOnCodeFullyEnteredListener.

private void setOnCodeFullyEnteredListener(VerificationCodeView verificationCodeView) {
    verificationCodeView.setOnCompleteListener(code -> {
        callMeCountDown.setVisibility(View.INVISIBLE);
        wrongNumber.setVisibility(View.INVISIBLE);
        keyboard.displayProgress();
        Disposable verify = viewModel.verifyCodeWithoutRegistrationLock(code).observeOn(AndroidSchedulers.mainThread()).subscribe(processor -> {
            if (!processor.hasResult()) {
                Log.w(TAG, "post verify: ", processor.getError());
            }
            if (processor.hasResult()) {
                handleSuccessfulVerify();
            } else if (processor.rateLimit()) {
                handleRateLimited();
            } else if (processor.registrationLock() && !processor.isKbsLocked()) {
                LockedException lockedException = processor.getLockedException();
                handleRegistrationLock(lockedException.getTimeRemaining());
            } else if (processor.isKbsLocked()) {
                handleKbsAccountLocked();
            } else if (processor.authorizationFailed()) {
                handleIncorrectCodeError();
            } else {
                Log.w(TAG, "Unable to verify code", processor.getError());
                handleGeneralError();
            }
        });
        disposables.add(verify);
    });
}
Also used : LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) LockedException(org.whispersystems.signalservice.internal.push.LockedException)

Aggregations

LockedException (org.whispersystems.signalservice.internal.push.LockedException)2 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 LifecycleDisposable (org.thoughtcrime.securesms.util.LifecycleDisposable)1 AuthorizationFailedException (org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException)1 CaptchaRequiredException (org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException)1 DeprecatedVersionException (org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException)1 ExpectationFailedException (org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException)1 MalformedResponseException (org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)1 NonSuccessfulResponseCodeException (org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException)1 NotFoundException (org.whispersystems.signalservice.api.push.exceptions.NotFoundException)1 ProofRequiredException (org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException)1 RateLimitException (org.whispersystems.signalservice.api.push.exceptions.RateLimitException)1 ServerRejectedException (org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException)1 AuthCredentials (org.whispersystems.signalservice.internal.push.AuthCredentials)1 DeviceLimit (org.whispersystems.signalservice.internal.push.DeviceLimit)1 DeviceLimitExceededException (org.whispersystems.signalservice.internal.push.DeviceLimitExceededException)1 MismatchedDevices (org.whispersystems.signalservice.internal.push.MismatchedDevices)1 ProofRequiredResponse (org.whispersystems.signalservice.internal.push.ProofRequiredResponse)1 PushServiceSocket (org.whispersystems.signalservice.internal.push.PushServiceSocket)1 StaleDevices (org.whispersystems.signalservice.internal.push.StaleDevices)1