Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade transport to 8.4.0 #40

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"zx": "^7.2.2"
},
"dependencies": {
"@elastic/transport": "^8.3.2",
"@elastic/transport": "^8.4.0",
"tslib": "^2.5.0"
},
"tap": {
Expand Down
11 changes: 9 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
BearerAuth,
Context
} from '@elastic/transport/lib/types'
import { RedactionOptions } from '@elastic/transport/lib/Transport'
import BaseConnection, { prepareHeaders } from '@elastic/transport/lib/connection/BaseConnection'
import Helpers from './helpers'
import API from './api'
Expand Down Expand Up @@ -104,6 +105,7 @@ export interface ClientOptions {
caFingerprint?: string
maxResponseSize?: number
maxCompressedResponseSize?: number
redaction?: RedactionOptions
}

export default class Client extends API {
Expand Down Expand Up @@ -173,7 +175,11 @@ export default class Client extends API {
proxy: null,
enableMetaHeader: true,
maxResponseSize: null,
maxCompressedResponseSize: null
maxCompressedResponseSize: null,
redaction: {
type: 'replace',
additionalKeys: []
}
}, opts)

if (options.caFingerprint != null && isHttpConnection(opts.node ?? opts.nodes)) {
Expand Down Expand Up @@ -241,7 +247,8 @@ export default class Client extends API {
context: options.context,
productCheck: 'Elasticsearch',
maxResponseSize: options.maxResponseSize,
maxCompressedResponseSize: options.maxCompressedResponseSize
maxCompressedResponseSize: options.maxCompressedResponseSize,
redaction: options.redaction
})

this.helpers = new Helpers({
Expand Down
12 changes: 9 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@ export default class Helpers {
await sleep(wait)
}
assert(response !== undefined, 'The response is undefined, please file a bug report')

const { redaction = { type: 'replace' } } = options
const errorOptions = { redaction }
if (response.statusCode === 429) {
throw new ResponseError(response)
throw new ResponseError(response, errorOptions)
}

let scroll_id = response.body._scroll_id
Expand Down Expand Up @@ -234,7 +237,7 @@ export default class Helpers {
await sleep(wait)
}
if (response.statusCode === 429) {
throw new ResponseError(response)
throw new ResponseError(response, errorOptions)
}
}

Expand Down Expand Up @@ -286,6 +289,9 @@ export default class Helpers {
} = options
reqOptions.meta = true

const { redaction = { type: 'replace' } } = reqOptions
const errorOptions = { redaction }

let stopReading = false
let stopError: Error | null = null
let timeoutRef = null
Expand Down Expand Up @@ -499,7 +505,7 @@ export default class Helpers {
// @ts-expect-error
addDocumentsGetter(result)
if (response.status != null && response.status >= 400) {
callbacks[i](new ResponseError(result), result)
callbacks[i](new ResponseError(result, errorOptions), result)
} else {
callbacks[i](null, result)
}
Expand Down