File tree 4 files changed +33
-0
lines changed
main/java/com/auth0/guardian 4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public class GuardianException extends RuntimeException {
35
35
private static final String ERROR_DEVICE_ACCOUNT_NOT_FOUND = "device_account_not_found" ;
36
36
private static final String ERROR_ENROLLMENT_NOT_FOUND = "enrollment_not_found" ;
37
37
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" ;
38
39
39
40
private static final String ERROR_ALREADY_ENROLLED = "already_enrolled" ;
40
41
@@ -106,6 +107,15 @@ public boolean isLoginTransactionNotFound() {
106
107
return ERROR_LOGIN_TRANSACTION_NOT_FOUND .equals (errorCode );
107
108
}
108
109
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
+
109
119
/**
110
120
* Whether the error is caused by the user already having a confirmed enrollment
111
121
*
Original file line number Diff line number Diff line change @@ -215,6 +215,24 @@ public void shouldThrowLoginTransactionNotFound() throws Exception {
215
215
}
216
216
}
217
217
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
+
218
236
@ Test
219
237
public void shouldThrowInvalidOTP () throws Exception {
220
238
exception .expect (GuardianException .class );
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ public class MockServer {
47
47
public static final String ERROR_DEVICE_ACCOUNT_NOT_FOUND = "src/test/resources/error_code_device_account_not_found.json" ;
48
48
public static final String ERROR_ENROLLMENT_NOT_FOUND = "src/test/resources/error_code_enrollment_not_found.json" ;
49
49
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" ;
50
51
public static final String ERROR_INVALID_TOKEN = "src/test/resources/error_code_invalid_token.json" ;
51
52
52
53
private final MockWebServer server ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "error" : " Not found" ,
3
+ "errorCode" : " transaction_not_found"
4
+ }
You can’t perform that action at this time.
0 commit comments