|
25 | 25 | import neo4j.org.testkit.backend.TestkitState;
|
26 | 26 | import neo4j.org.testkit.backend.messages.responses.DomainNameResolutionRequired;
|
27 | 27 | import neo4j.org.testkit.backend.messages.responses.Driver;
|
| 28 | +import neo4j.org.testkit.backend.messages.responses.DriverError; |
28 | 29 | import neo4j.org.testkit.backend.messages.responses.ResolverResolutionRequired;
|
29 | 30 | import neo4j.org.testkit.backend.messages.responses.TestkitErrorResponse;
|
30 | 31 | import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
|
@@ -82,7 +83,16 @@ public TestkitResponse process( TestkitState testkitState )
|
82 | 83 | }
|
83 | 84 | Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
|
84 | 85 | Optional.ofNullable( data.connectionTimeoutMs ).ifPresent( timeout -> configBuilder.withConnectionTimeout( timeout, TimeUnit.MILLISECONDS ) );
|
85 |
| - testkitState.getDrivers().putIfAbsent( id, driver( URI.create( data.uri ), authToken, configBuilder.build(), domainNameResolver ) ); |
| 86 | + org.neo4j.driver.Driver driver; |
| 87 | + try |
| 88 | + { |
| 89 | + driver = driver( URI.create( data.uri ), authToken, configBuilder.build(), domainNameResolver ); |
| 90 | + } |
| 91 | + catch ( RuntimeException e ) |
| 92 | + { |
| 93 | + return handleExceptionAsErrorResponse( testkitState, e ).orElseThrow( () -> e ); |
| 94 | + } |
| 95 | + testkitState.getDrivers().putIfAbsent( id, driver ); |
86 | 96 | return Driver.builder().data( Driver.DriverBody.builder().id( id ).build() ).build();
|
87 | 97 | }
|
88 | 98 |
|
@@ -137,6 +147,20 @@ private org.neo4j.driver.Driver driver( URI uri, AuthToken authToken, Config con
|
137 | 147 | .newInstance( uri, authToken, routingSettings, retrySettings, config, securityPlan );
|
138 | 148 | }
|
139 | 149 |
|
| 150 | + private Optional<TestkitResponse> handleExceptionAsErrorResponse( TestkitState testkitState, RuntimeException e ) |
| 151 | + { |
| 152 | + Optional<TestkitResponse> response = Optional.empty(); |
| 153 | + if ( e instanceof IllegalArgumentException && e.getMessage().startsWith( DriverFactory.NO_ROUTING_CONTEXT_ERROR_MESSAGE ) ) |
| 154 | + { |
| 155 | + String id = testkitState.newId(); |
| 156 | + String errorType = e.getClass().getName(); |
| 157 | + response = Optional.of( |
| 158 | + DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).errorType( errorType ).build() ).build() |
| 159 | + ); |
| 160 | + } |
| 161 | + return response; |
| 162 | + } |
| 163 | + |
140 | 164 | @Setter
|
141 | 165 | @Getter
|
142 | 166 | @NoArgsConstructor
|
|
0 commit comments