@@ -21,22 +21,13 @@ import {
21
21
import { DocumentSelector } from '../types/document'
22
22
import { isFunction , tryCatchPromise } from '../util'
23
23
import { Connection , createConnection } from './connection'
24
- import {
25
- CloseAction ,
26
- DefaultErrorHandler ,
27
- ErrorAction ,
28
- ErrorHandler ,
29
- InitializationFailedHandler ,
30
- } from './errorHandler'
24
+ import { CloseAction , DefaultErrorHandler , ErrorAction , ErrorHandler } from './errorHandler'
31
25
import { DynamicFeature , RegistrationData , StaticFeature } from './features/common'
32
26
33
27
/** Options for creating a new client. */
34
28
export interface ClientOptions {
35
29
documentSelector ?: DocumentSelector
36
30
37
- /** Called when initialization fails to determine how to proceed. */
38
- initializationFailedHandler ?: InitializationFailedHandler
39
-
40
31
/** Called when an error or close occurs to determine how to proceed. */
41
32
errorHandler ?: ErrorHandler
42
33
@@ -59,7 +50,6 @@ export interface ClientOptions {
59
50
60
51
/** The client options, after defaults have been set that make certain fields required. */
61
52
interface ResolvedClientOptions extends Pick < ClientOptions , Exclude < keyof ClientOptions , 'trace' > > {
62
- initializationFailedHandler : InitializationFailedHandler
63
53
errorHandler : ErrorHandler
64
54
tracer : Tracer
65
55
experimentalClientCapabilities : any
@@ -117,7 +107,6 @@ export class Client implements Unsubscribable {
117
107
public constructor ( public readonly id : string , { trace, ...options } : ClientOptions ) {
118
108
this . options = {
119
109
...options ,
120
- initializationFailedHandler : options . initializationFailedHandler || ( ( ) => Promise . resolve ( false ) ) ,
121
110
errorHandler : options . errorHandler || new DefaultErrorHandler ( ) ,
122
111
tracer : options . tracer || noopTracer ,
123
112
experimentalClientCapabilities : options . experimentalClientCapabilities || { } ,
@@ -142,10 +131,9 @@ export class Client implements Unsubscribable {
142
131
143
132
/**
144
133
* Activates the client, which causes it to start connecting (and to reestablish the connection when it drops,
145
- * as directed by the initializationFailedHandler ).
134
+ * as directed by the error handler ).
146
135
*
147
- * To watch client state, use Client#state. To log client errors, provide an initializationFailedHandler and
148
- * errorHandler in ClientOptions.
136
+ * To watch client state, use Client#state. To log client errors, provide errorHandler in ClientOptions.
149
137
*/
150
138
public activate ( ) : void {
151
139
// Callers should subscribe to Client#state instead of awaiting the activation.
@@ -238,17 +226,13 @@ export class Client implements Unsubscribable {
238
226
239
227
this . _state . next ( ClientState . Active )
240
228
} )
241
- . then ( null , err =>
242
- Promise . resolve ( this . options . initializationFailedHandler ( err ) ) . then ( reinitialize => {
243
- if ( reinitialize ) {
244
- return this . initialize ( connection )
245
- }
246
- if ( connection ) {
247
- connection . unsubscribe ( )
248
- }
249
- return this . stopAtState ( ClientState . ActivateFailed )
250
- } )
251
- )
229
+ . then ( null , err => {
230
+ this . options . errorHandler . error ( err , undefined , undefined )
231
+ if ( connection ) {
232
+ connection . unsubscribe ( )
233
+ }
234
+ return this . stopAtState ( ClientState . ActivateFailed )
235
+ } )
252
236
}
253
237
254
238
protected handleConnectionClosed ( ) : void {
0 commit comments