kopia lustrzana https://github.com/ryukoposting/Signal-Android
Ensure NonSuccessfulReponseCodeException knows the response code.
rodzic
015088a53f
commit
4482bfcabb
|
@ -262,7 +262,7 @@ public class SignalServiceMessagePipe {
|
|||
if (response.getStatus() == 404) {
|
||||
throw new NotFoundException("Not found");
|
||||
} else if (response.getStatus() < 200 || response.getStatus() >= 300) {
|
||||
throw new NonSuccessfulResponseCodeException("Non-successful response: " + response.getStatus());
|
||||
throw new NonSuccessfulResponseCodeException(response.getStatus(), "Non-successful response: " + response.getStatus());
|
||||
}
|
||||
|
||||
SignalServiceProfile signalServiceProfile = JsonUtil.fromJson(response.getBody(), SignalServiceProfile.class);
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMes
|
|||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException;
|
||||
|
@ -409,7 +410,9 @@ public class SignalServiceMessageSender {
|
|||
}
|
||||
}
|
||||
|
||||
private SignalServiceAttachmentPointer uploadAttachmentV2(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData) throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
private SignalServiceAttachmentPointer uploadAttachmentV2(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
AttachmentV2UploadAttributes v2UploadAttributes = null;
|
||||
Optional<SignalServiceMessagePipe> localPipe = pipe.get();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
public class AuthorizationFailedException extends NonSuccessfulResponseCodeException {
|
||||
public AuthorizationFailedException(String s) {
|
||||
super(s);
|
||||
public AuthorizationFailedException(int code, String s) {
|
||||
super(code, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
public class CaptchaRequiredException extends NonSuccessfulResponseCodeException {
|
||||
public CaptchaRequiredException() {
|
||||
super(402);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,6 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
*/
|
||||
public class ConflictException extends NonSuccessfulResponseCodeException {
|
||||
public ConflictException() {
|
||||
super("Conflict");
|
||||
super(409, "Conflict");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
public class DeprecatedVersionException extends NonSuccessfulResponseCodeException {
|
||||
public DeprecatedVersionException() {
|
||||
super(499);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,7 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
public class ExpectationFailedException extends NonSuccessfulResponseCodeException {
|
||||
public ExpectationFailedException() {
|
||||
super(417);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Indicates that a response is malformed or otherwise in an unexpected format.
|
||||
*/
|
||||
public class MalformedResponseException extends IOException {
|
||||
|
||||
public MalformedResponseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MalformedResponseException(String message, IOException e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,6 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
|
||||
public class NoContentException extends NonSuccessfulResponseCodeException {
|
||||
public NoContentException(String s) {
|
||||
super(s);
|
||||
super(204, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,23 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Indicates a server response that is not successful, typically something outside the 2xx range.
|
||||
*/
|
||||
public class NonSuccessfulResponseCodeException extends IOException {
|
||||
|
||||
public NonSuccessfulResponseCodeException() {
|
||||
super();
|
||||
private final int code;
|
||||
|
||||
public NonSuccessfulResponseCodeException(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public NonSuccessfulResponseCodeException(String s) {
|
||||
public NonSuccessfulResponseCodeException(int code, String s) {
|
||||
super(s);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
|
||||
public class NotFoundException extends NonSuccessfulResponseCodeException {
|
||||
public NotFoundException(String s) {
|
||||
super(s);
|
||||
super(404, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
public final class RangeException extends NonSuccessfulResponseCodeException {
|
||||
|
||||
public RangeException(long requested) {
|
||||
super("Range request out of bounds " + requested);
|
||||
super(416, "Range request out of bounds " + requested);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
|
||||
public class RateLimitException extends NonSuccessfulResponseCodeException {
|
||||
public RateLimitException(String s) {
|
||||
super(s);
|
||||
super(413, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
|
||||
public class RemoteAttestationResponseExpiredException extends NonSuccessfulResponseCodeException {
|
||||
public RemoteAttestationResponseExpiredException(String message) {
|
||||
super(message);
|
||||
super(409, message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,7 @@ package org.whispersystems.signalservice.api.push.exceptions;
|
|||
* Indicates the server has rejected the request and we should stop retrying.
|
||||
*/
|
||||
public class ServerRejectedException extends NonSuccessfulResponseCodeException {
|
||||
public ServerRejectedException() {
|
||||
super(508);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
public class UsernameMalformedException extends NonSuccessfulResponseCodeException {
|
||||
public UsernameMalformedException() {
|
||||
super(400);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package org.whispersystems.signalservice.api.push.exceptions;
|
||||
|
||||
public class UsernameTakenException extends NonSuccessfulResponseCodeException {
|
||||
public UsernameTakenException() {
|
||||
super(409);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ public class DeviceLimitExceededException extends NonSuccessfulResponseCodeExcep
|
|||
private final DeviceLimit deviceLimit;
|
||||
|
||||
public DeviceLimitExceededException(DeviceLimit deviceLimit) {
|
||||
super(411);
|
||||
this.deviceLimit = deviceLimit;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ public final class LockedException extends NonSuccessfulResponseCodeException {
|
|||
private final String basicStorageCredentials;
|
||||
|
||||
LockedException(int length, long timeRemaining, String basicStorageCredentials) {
|
||||
super(423);
|
||||
this.length = length;
|
||||
this.timeRemaining = timeRemaining;
|
||||
this.basicStorageCredentials = basicStorageCredentials;
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.whispersystems.signalservice.api.push.exceptions.ConflictException;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.ContactManifestMismatchException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NoContentException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
|
@ -623,13 +624,13 @@ public class PushServiceSocket {
|
|||
return JsonUtil.fromJson(body, SignalServiceProfile.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public SignalServiceProfile retrieveProfileByUsername(String username, Optional<UnidentifiedAccess> unidentifiedAccess)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
String response = makeServiceRequest(String.format(PROFILE_USERNAME_PATH, username), "GET", null, NO_HEADERS, unidentifiedAccess);
|
||||
|
||||
|
@ -637,7 +638,7 @@ public class PushServiceSocket {
|
|||
return JsonUtil.fromJson(response, SignalServiceProfile.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -656,7 +657,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
private ProfileAndCredential formatProfileAndCredentialBody(ProfileKeyCredentialRequestContext requestContext, String body)
|
||||
throws NonSuccessfulResponseCodeException
|
||||
throws MalformedResponseException
|
||||
{
|
||||
try {
|
||||
SignalServiceProfile signalServiceProfile = JsonUtil.fromJson(body, SignalServiceProfile.class);
|
||||
|
@ -672,7 +673,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -688,7 +689,7 @@ public class PushServiceSocket {
|
|||
return JsonUtil.fromJson(body, SignalServiceProfile.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -707,7 +708,7 @@ public class PushServiceSocket {
|
|||
* @return The avatar URL path, if one was written.
|
||||
*/
|
||||
public Optional<String> writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
String requestBody = JsonUtil.toJson(signalServiceProfileWrite);
|
||||
ProfileAvatarUploadAttributes formAttributes;
|
||||
|
@ -719,7 +720,7 @@ public class PushServiceSocket {
|
|||
formAttributes = JsonUtil.fromJson(response, ProfileAvatarUploadAttributes.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
|
||||
uploadToCdn0(AVATAR_UPLOAD_PATH, formAttributes.getAcl(), formAttributes.getKey(),
|
||||
|
@ -756,7 +757,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
public List<ContactTokenDetails> retrieveDirectory(Set<String> contactTokens)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
try {
|
||||
ContactTokenList contactTokenList = new ContactTokenList(new LinkedList<>(contactTokens));
|
||||
|
@ -766,7 +767,7 @@ public class PushServiceSocket {
|
|||
return activeTokens.getContacts();
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -801,7 +802,7 @@ public class PushServiceSocket {
|
|||
if (body != null) {
|
||||
return JsonUtil.fromJson(body.string(), TokenResponse.class);
|
||||
} else {
|
||||
throw new NonSuccessfulResponseCodeException("Empty response!");
|
||||
throw new MalformedResponseException("Empty response!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -813,7 +814,7 @@ public class PushServiceSocket {
|
|||
if (body != null) {
|
||||
return JsonUtil.fromJson(body.string(), DiscoveryResponse.class);
|
||||
} else {
|
||||
throw new NonSuccessfulResponseCodeException("Empty response!");
|
||||
throw new MalformedResponseException("Empty response!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -825,7 +826,7 @@ public class PushServiceSocket {
|
|||
if (body != null) {
|
||||
return JsonUtil.fromJson(body.string(), KeyBackupResponse.class);
|
||||
} else {
|
||||
throw new NonSuccessfulResponseCodeException("Empty response!");
|
||||
throw new MalformedResponseException("Empty response!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -899,23 +900,27 @@ public class PushServiceSocket {
|
|||
}
|
||||
}
|
||||
|
||||
public AttachmentV2UploadAttributes getAttachmentV2UploadAttributes() throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
public AttachmentV2UploadAttributes getAttachmentV2UploadAttributes()
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
String response = makeServiceRequest(ATTACHMENT_V2_PATH, "GET", null);
|
||||
try {
|
||||
return JsonUtil.fromJson(response, AttachmentV2UploadAttributes.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
}
|
||||
|
||||
public AttachmentV3UploadAttributes getAttachmentV3UploadAttributes() throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
public AttachmentV3UploadAttributes getAttachmentV3UploadAttributes()
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
String response = makeServiceRequest(ATTACHMENT_V3_PATH, "GET", null);
|
||||
try {
|
||||
return JsonUtil.fromJson(response, AttachmentV3UploadAttributes.class);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1053,7 +1058,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
}
|
||||
|
||||
throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
}
|
||||
|
||||
private byte[] uploadToCdn0(String path, String acl, String key, String policy, String algorithm,
|
||||
|
@ -1109,7 +1114,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
if (response.isSuccessful()) return file.getTransmittedDigest();
|
||||
else throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
else throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
} finally {
|
||||
synchronized (connections) {
|
||||
connections.remove(call);
|
||||
|
@ -1159,7 +1164,7 @@ public class PushServiceSocket {
|
|||
if (response.isSuccessful()) {
|
||||
return response.header("location");
|
||||
} else {
|
||||
throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
}
|
||||
} finally {
|
||||
synchronized (connections) {
|
||||
|
@ -1211,7 +1216,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
if (response.isSuccessful()) return file.getTransmittedDigest();
|
||||
else throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
else throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
} finally {
|
||||
synchronized (connections) {
|
||||
connections.remove(call);
|
||||
|
@ -1269,7 +1274,7 @@ public class PushServiceSocket {
|
|||
} else if (response.code() == 404) {
|
||||
throw new ResumeLocationInvalidException();
|
||||
} else {
|
||||
throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
}
|
||||
} finally {
|
||||
synchronized (connections) {
|
||||
|
@ -1300,31 +1305,31 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
private String makeServiceRequest(String urlFragment, String method, String jsonBody)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
return makeServiceRequest(urlFragment, method, jsonBody, NO_HEADERS, NO_HANDLER, Optional.<UnidentifiedAccess>absent());
|
||||
}
|
||||
|
||||
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
return makeServiceRequest(urlFragment, method, jsonBody, headers, NO_HANDLER, Optional.<UnidentifiedAccess>absent());
|
||||
}
|
||||
|
||||
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers, ResponseCodeHandler responseCodeHandler)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
return makeServiceRequest(urlFragment, method, jsonBody, headers, responseCodeHandler, Optional.<UnidentifiedAccess>absent());
|
||||
}
|
||||
|
||||
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers, Optional<UnidentifiedAccess> unidentifiedAccessKey)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
return makeServiceRequest(urlFragment, method, jsonBody, headers, NO_HANDLER, unidentifiedAccessKey);
|
||||
}
|
||||
|
||||
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers, ResponseCodeHandler responseCodeHandler, Optional<UnidentifiedAccess> unidentifiedAccessKey)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
ResponseBody responseBody = makeServiceBodyRequest(urlFragment, method, jsonRequestBody(jsonBody), headers, responseCodeHandler, unidentifiedAccessKey);
|
||||
try {
|
||||
|
@ -1382,7 +1387,7 @@ public class PushServiceSocket {
|
|||
Map<String, String> headers,
|
||||
ResponseCodeHandler responseCodeHandler,
|
||||
Optional<UnidentifiedAccess> unidentifiedAccessKey)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
return makeServiceRequest(urlFragment, method, body, headers, responseCodeHandler, unidentifiedAccessKey).body();
|
||||
}
|
||||
|
@ -1393,7 +1398,7 @@ public class PushServiceSocket {
|
|||
Map<String, String> headers,
|
||||
ResponseCodeHandler responseCodeHandler,
|
||||
Optional<UnidentifiedAccess> unidentifiedAccessKey)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
|
||||
{
|
||||
Response response = getServiceConnection(urlFragment, method, body, headers, unidentifiedAccessKey);
|
||||
|
||||
|
@ -1402,7 +1407,8 @@ public class PushServiceSocket {
|
|||
return validateServiceResponse(response);
|
||||
}
|
||||
|
||||
private Response validateServiceResponse(Response response) throws NonSuccessfulResponseCodeException, PushNetworkException {
|
||||
private Response validateServiceResponse(Response response)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
|
||||
int responseCode = response.code();
|
||||
String responseMessage = response.message();
|
||||
|
||||
|
@ -1411,7 +1417,7 @@ public class PushServiceSocket {
|
|||
throw new RateLimitException("Rate limit exceeded: " + responseCode);
|
||||
case 401:
|
||||
case 403:
|
||||
throw new AuthorizationFailedException("Authorization failed!");
|
||||
throw new AuthorizationFailedException(responseCode, "Authorization failed!");
|
||||
case 404:
|
||||
throw new NotFoundException("Not found");
|
||||
case 409:
|
||||
|
@ -1444,7 +1450,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
if (responseCode != 200 && responseCode != 204) {
|
||||
throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage);
|
||||
throw new NonSuccessfulResponseCodeException(responseCode, "Bad response: " + responseCode + " " + responseMessage);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
@ -1591,14 +1597,14 @@ public class PushServiceSocket {
|
|||
switch (response.code()) {
|
||||
case 401:
|
||||
case 403:
|
||||
throw new AuthorizationFailedException("Authorization failed!");
|
||||
throw new AuthorizationFailedException(response.code(), "Authorization failed!");
|
||||
case 409:
|
||||
throw new RemoteAttestationResponseExpiredException("Remote attestation response expired");
|
||||
case 429:
|
||||
throw new RateLimitException("Rate limit exceeded: " + response.code());
|
||||
}
|
||||
|
||||
throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
}
|
||||
|
||||
private ResponseBody makeStorageRequest(String authorization, String path, String method, RequestBody body)
|
||||
|
@ -1665,7 +1671,7 @@ public class PushServiceSocket {
|
|||
throw new NoContentException("No content!");
|
||||
case 401:
|
||||
case 403:
|
||||
throw new AuthorizationFailedException("Authorization failed!");
|
||||
throw new AuthorizationFailedException(response.code(), "Authorization failed!");
|
||||
case 404:
|
||||
throw new NotFoundException("Not found");
|
||||
case 409:
|
||||
|
@ -1680,7 +1686,7 @@ public class PushServiceSocket {
|
|||
throw new DeprecatedVersionException();
|
||||
}
|
||||
|
||||
throw new NonSuccessfulResponseCodeException("Response: " + response);
|
||||
throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
|
||||
}
|
||||
|
||||
public CallingResponse makeCallingRequest(long requestId, String url, String httpMethod, List<Pair<String, String>> headers, byte[] body) {
|
||||
|
@ -1852,17 +1858,15 @@ public class PushServiceSocket {
|
|||
|
||||
/**
|
||||
* Converts {@link IOException} on body reading to {@link PushNetworkException}.
|
||||
* {@link IOException} during json parsing is converted to a {@link NonSuccessfulResponseCodeException}
|
||||
* {@link IOException} during json parsing is converted to a {@link MalformedResponseException}
|
||||
*/
|
||||
private static <T> T readBodyJson(ResponseBody body, Class<T> clazz)
|
||||
throws PushNetworkException, NonSuccessfulResponseCodeException
|
||||
{
|
||||
private static <T> T readBodyJson(ResponseBody body, Class<T> clazz) throws PushNetworkException, MalformedResponseException {
|
||||
String json = readBodyString(body);
|
||||
try {
|
||||
return JsonUtil.fromJson(json, clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse entity");
|
||||
throw new MalformedResponseException("Unable to parse entity", e);
|
||||
} catch (IOException e) {
|
||||
throw new PushNetworkException(e);
|
||||
}
|
||||
|
@ -1873,13 +1877,9 @@ public class PushServiceSocket {
|
|||
* {@link IOException} during json parsing is converted to a {@link NonSuccessfulResponseCodeException} with response code detail.
|
||||
*/
|
||||
private static <T> T readResponseJson(Response response, Class<T> clazz)
|
||||
throws PushNetworkException, NonSuccessfulResponseCodeException
|
||||
throws PushNetworkException, MalformedResponseException
|
||||
{
|
||||
try {
|
||||
return readBodyJson(response.body(), clazz);
|
||||
} catch (NonSuccessfulResponseCodeException e) {
|
||||
throw new NonSuccessfulResponseCodeException("Bad response: " + response.code() + " " + response.message());
|
||||
}
|
||||
}
|
||||
|
||||
private static class GcmRegistrationId {
|
||||
|
@ -2066,7 +2066,7 @@ public class PushServiceSocket {
|
|||
}
|
||||
|
||||
public GroupHistory getGroupsV2GroupHistory(int fromVersion, GroupsV2AuthorizationString authorization)
|
||||
throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException
|
||||
throws IOException, InvalidProtocolBufferException
|
||||
{
|
||||
Response response = makeStorageRequestResponse(authorization.toString(),
|
||||
String.format(Locale.US, GROUPSV2_GROUP_CHANGES, fromVersion),
|
||||
|
@ -2085,7 +2085,7 @@ public class PushServiceSocket {
|
|||
return new GroupHistory(groupChanges, contentRange);
|
||||
} else {
|
||||
Log.w(TAG, "Unable to parse Content-Range header: " + contentRangeHeader);
|
||||
throw new NonSuccessfulResponseCodeException("Unable to parse content range header on 206");
|
||||
throw new MalformedResponseException("Unable to parse content range header on 206");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.whispersystems.libsignal.InvalidKeyException;
|
|||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.signalservice.internal.contacts.crypto.Quote;
|
||||
import org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation;
|
||||
|
@ -61,7 +62,7 @@ public final class RemoteAttestationUtil {
|
|||
Map<String, RemoteAttestation> attestations = new HashMap<>();
|
||||
|
||||
if (response.getAttestations().isEmpty() || response.getAttestations().size() > 3) {
|
||||
throw new NonSuccessfulResponseCodeException("Incorrect number of attestations: " + response.getAttestations().size());
|
||||
throw new MalformedResponseException("Incorrect number of attestations: " + response.getAttestations().size());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, RemoteAttestationResponse> entry : response.getAttestations().entrySet()) {
|
||||
|
@ -92,7 +93,7 @@ public final class RemoteAttestationUtil {
|
|||
ResponseBody body = response.body();
|
||||
|
||||
if (body == null) {
|
||||
throw new NonSuccessfulResponseCodeException("Empty response!");
|
||||
throw new MalformedResponseException("Empty response!");
|
||||
}
|
||||
|
||||
return new ResponsePair(body.string(), parseCookies(response));
|
||||
|
|
|
@ -3,4 +3,7 @@ package org.whispersystems.signalservice.internal.push.exceptions;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
|
||||
public final class ForbiddenException extends NonSuccessfulResponseCodeException {
|
||||
public ForbiddenException() {
|
||||
super(403);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,7 @@ package org.whispersystems.signalservice.internal.push.exceptions;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
|
||||
public final class GroupExistsException extends NonSuccessfulResponseCodeException {
|
||||
public GroupExistsException() {
|
||||
super(409);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,7 @@ package org.whispersystems.signalservice.internal.push.exceptions;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
|
||||
public final class GroupNotFoundException extends NonSuccessfulResponseCodeException {
|
||||
public GroupNotFoundException() {
|
||||
super(404);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,7 @@ package org.whispersystems.signalservice.internal.push.exceptions;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
|
||||
public final class GroupPatchNotAcceptedException extends NonSuccessfulResponseCodeException {
|
||||
public GroupPatchNotAcceptedException() {
|
||||
super(400);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class MismatchedDevicesException extends NonSuccessfulResponseCodeExcepti
|
|||
private final MismatchedDevices mismatchedDevices;
|
||||
|
||||
public MismatchedDevicesException(MismatchedDevices mismatchedDevices) {
|
||||
super(409);
|
||||
this.mismatchedDevices = mismatchedDevices;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,4 +3,7 @@ package org.whispersystems.signalservice.internal.push.exceptions;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
|
||||
public final class NotInGroupException extends NonSuccessfulResponseCodeException {
|
||||
public NotInGroupException() {
|
||||
super(403);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class StaleDevicesException extends NonSuccessfulResponseCodeException {
|
|||
private final StaleDevices staleDevices;
|
||||
|
||||
public StaleDevicesException(StaleDevices staleDevices) {
|
||||
super(410);
|
||||
this.staleDevices = staleDevices;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue