|
17 | 17 | package org.whispersystems.textsecure.internal.push; |
18 | 18 |
|
19 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 20 | +import com.fasterxml.jackson.core.JsonProcessingException; |
20 | 21 |
|
21 | 22 | import org.apache.http.conn.ssl.StrictHostnameVerifier; |
22 | 23 | import org.whispersystems.libaxolotl.IdentityKey; |
@@ -259,8 +260,6 @@ public List<PreKeyBundle> getPreKeys(TextSecureAddress destination, int deviceId |
259 | 260 | } |
260 | 261 |
|
261 | 262 | return bundles; |
262 | | - } catch (JsonUtil.JsonParseException e) { |
263 | | - throw new IOException(e); |
264 | 263 | } catch (NotFoundException nfe) { |
265 | 264 | throw new UnregisteredUserException(destination.getNumber(), nfe); |
266 | 265 | } |
@@ -301,8 +300,6 @@ public PreKeyBundle getPreKey(TextSecureAddress destination, int deviceId) throw |
301 | 300 |
|
302 | 301 | return new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), preKeyId, preKey, |
303 | 302 | signedPreKeyId, signedPreKey, signedPreKeySignature, response.getIdentityKey()); |
304 | | - } catch (JsonUtil.JsonParseException e) { |
305 | | - throw new IOException(e); |
306 | 303 | } catch (NotFoundException nfe) { |
307 | 304 | throw new UnregisteredUserException(destination.getNumber(), nfe); |
308 | 305 | } |
@@ -359,11 +356,16 @@ public void retrieveAttachment(String relay, long attachmentId, File destination |
359 | 356 | public List<ContactTokenDetails> retrieveDirectory(Set<String> contactTokens) |
360 | 357 | throws NonSuccessfulResponseCodeException, PushNetworkException |
361 | 358 | { |
362 | | - ContactTokenList contactTokenList = new ContactTokenList(new LinkedList<>(contactTokens)); |
363 | | - String response = makeRequest(DIRECTORY_TOKENS_PATH, "PUT", JsonUtil.toJson(contactTokenList)); |
364 | | - ContactTokenDetailsList activeTokens = JsonUtil.fromJson(response, ContactTokenDetailsList.class); |
| 359 | + try { |
| 360 | + ContactTokenList contactTokenList = new ContactTokenList(new LinkedList<>(contactTokens)); |
| 361 | + String response = makeRequest(DIRECTORY_TOKENS_PATH, "PUT", JsonUtil.toJson(contactTokenList)); |
| 362 | + ContactTokenDetailsList activeTokens = JsonUtil.fromJson(response, ContactTokenDetailsList.class); |
365 | 363 |
|
366 | | - return activeTokens.getContacts(); |
| 364 | + return activeTokens.getContacts(); |
| 365 | + } catch (IOException e) { |
| 366 | + Log.w(TAG, e); |
| 367 | + throw new NonSuccessfulResponseCodeException("Unable to parse entity"); |
| 368 | + } |
367 | 369 | } |
368 | 370 |
|
369 | 371 | public ContactTokenDetails getContactTokenDetails(String contactToken) throws IOException { |
@@ -501,26 +503,45 @@ private HttpURLConnection makeBaseRequest(String urlFragment, String method, Str |
501 | 503 | connection.disconnect(); |
502 | 504 | throw new NotFoundException("Not found"); |
503 | 505 | case 409: |
| 506 | + MismatchedDevices mismatchedDevices; |
| 507 | + |
504 | 508 | try { |
505 | | - response = Util.readFully(connection.getErrorStream()); |
| 509 | + response = Util.readFully(connection.getErrorStream()); |
| 510 | + mismatchedDevices = JsonUtil.fromJson(response, MismatchedDevices.class); |
| 511 | + } catch (JsonProcessingException e) { |
| 512 | + Log.w(TAG, e); |
| 513 | + throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); |
506 | 514 | } catch (IOException e) { |
507 | 515 | throw new PushNetworkException(e); |
508 | 516 | } |
509 | | - throw new MismatchedDevicesException(JsonUtil.fromJson(response, MismatchedDevices.class)); |
| 517 | + |
| 518 | + throw new MismatchedDevicesException(mismatchedDevices); |
510 | 519 | case 410: |
| 520 | + StaleDevices staleDevices; |
| 521 | + |
511 | 522 | try { |
512 | | - response = Util.readFully(connection.getErrorStream()); |
| 523 | + response = Util.readFully(connection.getErrorStream()); |
| 524 | + staleDevices = JsonUtil.fromJson(response, StaleDevices.class); |
| 525 | + } catch (JsonProcessingException e) { |
| 526 | + throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); |
513 | 527 | } catch (IOException e) { |
514 | 528 | throw new PushNetworkException(e); |
515 | 529 | } |
516 | | - throw new StaleDevicesException(JsonUtil.fromJson(response, StaleDevices.class)); |
| 530 | + |
| 531 | + throw new StaleDevicesException(staleDevices); |
517 | 532 | case 411: |
| 533 | + DeviceLimit deviceLimit; |
| 534 | + |
518 | 535 | try { |
519 | | - response = Util.readFully(connection.getErrorStream()); |
| 536 | + response = Util.readFully(connection.getErrorStream()); |
| 537 | + deviceLimit = JsonUtil.fromJson(response, DeviceLimit.class); |
| 538 | + } catch (JsonProcessingException e) { |
| 539 | + throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); |
520 | 540 | } catch (IOException e) { |
521 | 541 | throw new PushNetworkException(e); |
522 | 542 | } |
523 | | - throw new DeviceLimitExceededException(JsonUtil.fromJson(response, DeviceLimit.class)); |
| 543 | + |
| 544 | + throw new DeviceLimitExceededException(deviceLimit); |
524 | 545 | case 417: |
525 | 546 | throw new ExpectationFailedException(); |
526 | 547 | } |
|
0 commit comments