Skip to content

Commit f01310e

Browse files
committed
GuardianException: add isTransactionNotFound
1 parent 434ea3b commit f01310e

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/main/java/com/auth0/guardian/GuardianException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class GuardianException extends RuntimeException {
3535
private static final String ERROR_DEVICE_ACCOUNT_NOT_FOUND = "device_account_not_found";
3636
private static final String ERROR_ENROLLMENT_NOT_FOUND = "enrollment_not_found";
3737
private static final String ERROR_LOGIN_TRANSACTION_NOT_FOUND = "login_transaction_not_found";
38+
private static final String ERROR_TRANSACTION_NOT_FOUND = "transaction_not_found";
3839

3940
private static final String ERROR_ALREADY_ENROLLED = "already_enrolled";
4041

@@ -106,6 +107,15 @@ public boolean isLoginTransactionNotFound() {
106107
return ERROR_LOGIN_TRANSACTION_NOT_FOUND.equals(errorCode);
107108
}
108109

110+
/**
111+
* Whether the error is caused by the transaction being invalid, expired or not found (e.g. already confirmed)
112+
*
113+
* @return true if error is caused by the transaction being invalid, expired or not found
114+
*/
115+
public boolean isTransactionNotFound() {
116+
return ERROR_TRANSACTION_NOT_FOUND.equals(errorCode);
117+
}
118+
109119
/**
110120
* Whether the error is caused by the user already having a confirmed enrollment
111121
*

src/test/java/com/auth0/guardian/APIClientTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ public void shouldThrowLoginTransactionNotFound() throws Exception {
215215
}
216216
}
217217

218+
@Test
219+
public void shouldThrowTransactionNotFound() throws Exception {
220+
exception.expect(GuardianException.class);
221+
exception.expectMessage("Not found");
222+
223+
server.jsonResponse(MockServer.ERROR_TRANSACTION_NOT_FOUND, 400);
224+
225+
try {
226+
apiClient
227+
.verifyOTP(TRANSACTION_TOKEN, OTP_CODE)
228+
.execute();
229+
} catch (GuardianException e) {
230+
assertThat(e.getErrorCode(), is(equalTo("transaction_not_found")));
231+
assertThat(e.isTransactionNotFound(), is(equalTo(true)));
232+
throw e;
233+
}
234+
}
235+
218236
@Test
219237
public void shouldThrowInvalidOTP() throws Exception {
220238
exception.expect(GuardianException.class);

src/test/java/com/auth0/guardian/MockServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class MockServer {
4747
public static final String ERROR_DEVICE_ACCOUNT_NOT_FOUND = "src/test/resources/error_code_device_account_not_found.json";
4848
public static final String ERROR_ENROLLMENT_NOT_FOUND = "src/test/resources/error_code_enrollment_not_found.json";
4949
public static final String ERROR_LOGIN_TRANSACTION_NOT_FOUND = "src/test/resources/error_code_login_transaction_not_found.json";
50+
public static final String ERROR_TRANSACTION_NOT_FOUND = "src/test/resources/error_code_transaction_not_found.json";
5051
public static final String ERROR_INVALID_TOKEN = "src/test/resources/error_code_invalid_token.json";
5152

5253
private final MockWebServer server;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"error": "Not found",
3+
"errorCode": "transaction_not_found"
4+
}

0 commit comments

Comments
 (0)