Skip to content

Commit

Permalink
Fix 841 (#842)
Browse files Browse the repository at this point in the history
* Added errors to exported members

* Updated test
  • Loading branch information
delvedor committed May 9, 2019
1 parent 02ad9a9 commit 6d5b5f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export {
Connection,
Serializer,
events,
errors,
ApiResponse,
RequestEvent,
ResurrectEvent,
Expand Down
19 changes: 10 additions & 9 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,31 @@ import {
RequestEvent,
ResurrectEvent,
events,
errors,
ClientExtendsCallbackOptions
} from '../../index'

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

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

client.on(events.RESPONSE, (err: Error | null, request: RequestEvent) => {
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | null, request: RequestEvent) => {
if (err) console.log(err)
const { body, statusCode } = request
const { params } = request.meta.request
console.log(params, body, statusCode)
})
client.on(events.RESURRECT, (err: Error | null, meta: ResurrectEvent) => {})
client.on(events.RESURRECT, (err: errors.ElasticsearchClientError | null, meta: ResurrectEvent) => {})

// Callbacks
client.info((err: Error | null, result: ApiResponse) => {})
client.info((err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})

client.index({
index: 'test',
type: 'test',
id: 'test',
body: { hello: 'world' }
}, (err: Error | null, result: ApiResponse) => {})
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})

// request options
client.index({
Expand All @@ -65,12 +66,12 @@ client.index({
querystring: { baz: 'faz' },
compression: 'gzip',
asStream: false
}, (err: Error | null, result: ApiResponse) => {})
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})

// Promises
client.info()
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})

client.index({
index: 'test',
Expand All @@ -79,7 +80,7 @@ client.index({
body: { hello: 'world' }
})
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})

// request options
client.index({
Expand All @@ -93,7 +94,7 @@ client.index({
requestTimeout: 2000
})
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})

// --- Use generics ---
// Define the search parameters
Expand Down Expand Up @@ -127,7 +128,7 @@ interface Source {

client.search(searchParams)
.then((response: ApiResponse<SearchResponse<Source>>) => console.log(response))
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})

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

0 comments on commit 6d5b5f6

Please sign in to comment.