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