@@ -26,30 +26,31 @@ import {
26
26
RequestEvent ,
27
27
ResurrectEvent ,
28
28
events ,
29
+ errors ,
29
30
ClientExtendsCallbackOptions
30
31
} from '../../index'
31
32
32
33
import { TransportRequestParams , TransportRequestOptions } from '../../lib/Transport'
33
34
34
35
const client = new Client ( { node : 'http://localhost:9200' } )
35
36
36
- client . on ( events . RESPONSE , ( err : Error | null , request : RequestEvent ) => {
37
+ client . on ( events . RESPONSE , ( err : errors . ElasticsearchClientError | null , request : RequestEvent ) => {
37
38
if ( err ) console . log ( err )
38
39
const { body, statusCode } = request
39
40
const { params } = request . meta . request
40
41
console . log ( params , body , statusCode )
41
42
} )
42
- client . on ( events . RESURRECT , ( err : Error | null , meta : ResurrectEvent ) => { } )
43
+ client . on ( events . RESURRECT , ( err : errors . ElasticsearchClientError | null , meta : ResurrectEvent ) => { } )
43
44
44
45
// Callbacks
45
- client . info ( ( err : Error | null , result : ApiResponse ) => { } )
46
+ client . info ( ( err : errors . ElasticsearchClientError | null , result : ApiResponse ) => { } )
46
47
47
48
client . index ( {
48
49
index : 'test' ,
49
50
type : 'test' ,
50
51
id : 'test' ,
51
52
body : { hello : 'world' }
52
- } , ( err : Error | null , result : ApiResponse ) => { } )
53
+ } , ( err : errors . ElasticsearchClientError | null , result : ApiResponse ) => { } )
53
54
54
55
// request options
55
56
client . index ( {
@@ -65,12 +66,12 @@ client.index({
65
66
querystring : { baz : 'faz' } ,
66
67
compression : 'gzip' ,
67
68
asStream : false
68
- } , ( err : Error | null , result : ApiResponse ) => { } )
69
+ } , ( err : errors . ElasticsearchClientError | null , result : ApiResponse ) => { } )
69
70
70
71
// Promises
71
72
client . info ( )
72
73
. then ( ( result : ApiResponse ) => { } )
73
- . catch ( ( err : Error ) => { } )
74
+ . catch ( ( err : errors . ElasticsearchClientError ) => { } )
74
75
75
76
client . index ( {
76
77
index : 'test' ,
@@ -79,7 +80,7 @@ client.index({
79
80
body : { hello : 'world' }
80
81
} )
81
82
. then ( ( result : ApiResponse ) => { } )
82
- . catch ( ( err : Error ) => { } )
83
+ . catch ( ( err : errors . ElasticsearchClientError ) => { } )
83
84
84
85
// request options
85
86
client . index ( {
@@ -93,7 +94,7 @@ client.index({
93
94
requestTimeout : 2000
94
95
} )
95
96
. then ( ( result : ApiResponse ) => { } )
96
- . catch ( ( err : Error ) => { } )
97
+ . catch ( ( err : errors . ElasticsearchClientError ) => { } )
97
98
98
99
// --- Use generics ---
99
100
// Define the search parameters
@@ -127,7 +128,7 @@ interface Source {
127
128
128
129
client . search ( searchParams )
129
130
. then ( ( response : ApiResponse < SearchResponse < Source > > ) => console . log ( response ) )
130
- . catch ( ( err : Error ) => { } )
131
+ . catch ( ( err : errors . ElasticsearchClientError ) => { } )
131
132
132
133
// extend client
133
134
client . extend ( 'namespace.method' , ( options : ClientExtendsCallbackOptions ) => {
0 commit comments