ErrorUtil { public static Neo4jException newNeo4jError( String code, String message ) { String classification = extractClassification( code ); switch ( classification ) { case "ClientError": if ( code.equalsIgnoreCase( "Neo.ClientError.Security.Unauthorized" ) ) { return new AuthenticationException( code, message ); } else if ( code.equalsIgnoreCase( "Neo.ClientError.Database.DatabaseNotFound" ) ) { return new FatalDiscoveryException( code, message ); } else { return new ClientException( code, message ); } case "TransientError": return new TransientException( code, message ); default: return new DatabaseException( code, message ); } } private  ErrorUtil(); static ServiceUnavailableException newConnectionTerminatedError( String reason ); static ServiceUnavailableException newConnectionTerminatedError(); static ResultConsumedException newResultConsumedError(); static Neo4jException newNeo4jError( String code, String message ); static boolean isFatal( Throwable error ); static void rethrowAsyncException( ExecutionException e ); static void addSuppressed( Throwable mainError, Throwable error ); static Throwable getRootCause( Throwable error );  }
@Test void shouldCreateAuthenticationException() { String code = "Neo.ClientError.Security.Unauthorized"; String message = "Wrong credentials"; Neo4jException error = newNeo4jError( code, message ); assertThat( error, instanceOf( AuthenticationException.class ) ); assertEquals( code, error.code() ); assertEquals( message, error.getMessage() ); }
@Test void shouldCreateClientException() { String code = "Neo.ClientError.Transaction.InvalidBookmark"; String message = "Wrong bookmark"; Neo4jException error = newNeo4jError( code, message ); assertThat( error, instanceOf( ClientException.class ) ); assertEquals( code, error.code() ); assertEquals( message, error.getMessage() ); }
@Test void shouldCreateTransientException() { String code = "Neo.TransientError.Transaction.DeadlockDetected"; String message = "Deadlock occurred"; Neo4jException error = newNeo4jError( code, message ); assertThat( error, instanceOf( TransientException.class ) ); assertEquals( code, error.code() ); assertEquals( message, error.getMessage() ); }
@Test void shouldCreateDatabaseException() { String code = "Neo.DatabaseError.Transaction.TransactionLogError"; String message = "Failed to write the transaction log"; Neo4jException error = newNeo4jError( code, message ); assertThat( error, instanceOf( DatabaseException.class ) ); assertEquals( code, error.code() ); assertEquals( message, error.getMessage() ); }
@Test void shouldCreateDatabaseExceptionWhenErrorCodeIsWrong() { String code = "WrongErrorCode"; String message = "Some really strange error"; Neo4jException error = newNeo4jError( code, message ); assertThat( error, instanceOf( DatabaseException.class ) ); assertEquals( code, error.code() ); assertEquals( message, error.getMessage() ); }