Skip to content

Commit 6f27676

Browse files
committed
Fix 841 (#842)
* Added errors to exported members * Updated test
1 parent 9613778 commit 6f27676

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ export {
576576
Connection,
577577
Serializer,
578578
events,
579+
errors,
579580
ApiResponse,
580581
RequestEvent,
581582
ResurrectEvent,

test/types/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,31 @@ import {
2626
RequestEvent,
2727
ResurrectEvent,
2828
events,
29+
errors,
2930
ClientExtendsCallbackOptions
3031
} from '../../index'
3132

3233
import { TransportRequestParams, TransportRequestOptions } from '../../lib/Transport'
3334

3435
const client = new Client({ node: 'http://localhost:9200' })
3536

36-
client.on(events.RESPONSE, (err: Error | null, request: RequestEvent) => {
37+
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | null, request: RequestEvent) => {
3738
if (err) console.log(err)
3839
const { body, statusCode } = request
3940
const { params } = request.meta.request
4041
console.log(params, body, statusCode)
4142
})
42-
client.on(events.RESURRECT, (err: Error | null, meta: ResurrectEvent) => {})
43+
client.on(events.RESURRECT, (err: errors.ElasticsearchClientError | null, meta: ResurrectEvent) => {})
4344

4445
// Callbacks
45-
client.info((err: Error | null, result: ApiResponse) => {})
46+
client.info((err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
4647

4748
client.index({
4849
index: 'test',
4950
type: 'test',
5051
id: 'test',
5152
body: { hello: 'world' }
52-
}, (err: Error | null, result: ApiResponse) => {})
53+
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
5354

5455
// request options
5556
client.index({
@@ -65,12 +66,12 @@ client.index({
6566
querystring: { baz: 'faz' },
6667
compression: 'gzip',
6768
asStream: false
68-
}, (err: Error | null, result: ApiResponse) => {})
69+
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
6970

7071
// Promises
7172
client.info()
7273
.then((result: ApiResponse) => {})
73-
.catch((err: Error) => {})
74+
.catch((err: errors.ElasticsearchClientError) => {})
7475

7576
client.index({
7677
index: 'test',
@@ -79,7 +80,7 @@ client.index({
7980
body: { hello: 'world' }
8081
})
8182
.then((result: ApiResponse) => {})
82-
.catch((err: Error) => {})
83+
.catch((err: errors.ElasticsearchClientError) => {})
8384

8485
// request options
8586
client.index({
@@ -93,7 +94,7 @@ client.index({
9394
requestTimeout: 2000
9495
})
9596
.then((result: ApiResponse) => {})
96-
.catch((err: Error) => {})
97+
.catch((err: errors.ElasticsearchClientError) => {})
9798

9899
// --- Use generics ---
99100
// Define the search parameters
@@ -127,7 +128,7 @@ interface Source {
127128

128129
client.search(searchParams)
129130
.then((response: ApiResponse<SearchResponse<Source>>) => console.log(response))
130-
.catch((err: Error) => {})
131+
.catch((err: errors.ElasticsearchClientError) => {})
131132

132133
// extend client
133134
client.extend('namespace.method', (options: ClientExtendsCallbackOptions) => {

0 commit comments

Comments
 (0)