Skip to content

Commit 986e957

Browse files
Propagate JSON decoding error on webhook event verification in Java (#158)
1 parent cab4b26 commit 986e957

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

generators/java/okhttp-gson/templates/WebhookEventVerifier.mustache

+6-9
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ public class WebhookEventVerifier {
7676
* @param rawEventBody the raw event body
7777
* @param hexSignature the hex signature
7878
* @return the webhook event
79-
* @throws OnfidoInvalidSignatureError the onfido exception
79+
* @throws OnfidoInvalidSignatureError on verification error
80+
* @throws JsonParseException on JSON parsing error
8081
*/
8182
public WebhookEvent readPayload(String rawEventBody, String hexSignature)
82-
throws OnfidoInvalidSignatureError {
83+
throws OnfidoInvalidSignatureError, JsonParseException {
8384
Mac sha256Hmac;
8485
SecretKeySpec secretKey;
8586
@@ -100,14 +101,10 @@ public class WebhookEventVerifier {
100101
throw new OnfidoInvalidSignatureError("Invalid signature for webhook event");
101102
}
102103

103-
try {
104-
JsonReader jsonReader = new JsonReader(new StringReader(rawEventBody));
105-
jsonReader.setLenient(true);
104+
JsonReader jsonReader = new JsonReader(new StringReader(rawEventBody));
105+
jsonReader.setLenient(true);
106106

107-
return gson.fromJson(jsonReader, WebhookEvent.class);
108-
} catch (JsonParseException e) {
109-
throw new OnfidoInvalidSignatureError("Invalid payload for webhook event", e);
110-
}
107+
return gson.fromJson(jsonReader, WebhookEvent.class);
111108
}
112109

113110
private String encodeHexString(byte[] byteArray) {

0 commit comments

Comments
 (0)