Skip to content

Commit

Permalink
Improved exception handling in Calendar.java
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoreficint committed Jan 18, 2021
1 parent 9b93afa commit 638899b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main/java/com/eternitywall/ots/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public Timestamp submit(byte[] digest) throws ExceededSizeException, UrlExceptio

StreamDeserializationContext ctx = new StreamDeserializationContext(body);
return Timestamp.deserialize(ctx, digest);
} catch (Exception e) {
} catch (ExceededSizeException e)
{
throw e;
}
catch (Exception e) {
throw new UrlException(e.getMessage());
}
}
Expand All @@ -101,11 +105,12 @@ public Timestamp submit(byte[] digest) throws ExceededSizeException, UrlExceptio
*
* @param commitment The digest hash to send.
* @return the Timestamp from the calendar server (with blockchain information if already written).
* @throws DeserializationException if response is too big.
* @throws ExceededSizeException if response is too big.
* @throws UrlException if url is not reachable.
* @throws CommitmentNotFoundException if commit is not found.
* @throws DeserializationException if the data is corrupt
*/
public Timestamp getTimestamp(byte[] commitment) throws DeserializationException, CommitmentNotFoundException, UrlException {
public Timestamp getTimestamp(byte[] commitment) throws DeserializationException, ExceededSizeException, CommitmentNotFoundException, UrlException {
try {
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "application/vnd.opentimestamps.v1");
Expand All @@ -118,7 +123,7 @@ public Timestamp getTimestamp(byte[] commitment) throws DeserializationException
Response response = task.call();
byte[] body = response.getBytes();
if (body.length > 10000) {
throw new DeserializationException("Calendar response exceeded size limit");
throw new ExceededSizeException("Calendar response exceeded size limit");
}

if (!response.isOk()) {
Expand All @@ -128,7 +133,12 @@ public Timestamp getTimestamp(byte[] commitment) throws DeserializationException
StreamDeserializationContext ctx = new StreamDeserializationContext(body);

return Timestamp.deserialize(ctx, commitment);
} catch (Exception e) {
}
catch (DeserializationException | ExceededSizeException | CommitmentNotFoundException e)
{
throw e;
}
catch (Exception e) {
throw new UrlException(e.getMessage());
}
}
Expand Down

0 comments on commit 638899b

Please sign in to comment.