From a65c4761bd0a0310607bcba151f9a037e39a76d2 Mon Sep 17 00:00:00 2001 From: Daniel Getu Date: Mon, 23 Jan 2023 11:27:08 -0800 Subject: [PATCH] [Search] Fix discarded user-defined `onResponse` callback (#24479) --- sdk/search/search-documents/CHANGELOG.md | 2 ++ sdk/search/search-documents/src/searchClient.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sdk/search/search-documents/CHANGELOG.md b/sdk/search/search-documents/CHANGELOG.md index 2e46a5783c8f..51d4c73a1eef 100644 --- a/sdk/search/search-documents/CHANGELOG.md +++ b/sdk/search/search-documents/CHANGELOG.md @@ -12,6 +12,8 @@ ### Bugs Fixed +- Fix discarded user-defined `onResponse` callback [#24479](https://github.com/Azure/azure-sdk-for-js/pull/24479) + ### Other Changes ## 11.3.0-beta.8 (2022-09-06) diff --git a/sdk/search/search-documents/src/searchClient.ts b/sdk/search/search-documents/src/searchClient.ts index 451dea336eff..9d8cccabbc52 100644 --- a/sdk/search/search-documents/src/searchClient.ts +++ b/sdk/search/search-documents/src/searchClient.ts @@ -207,8 +207,11 @@ export class SearchClient implements IndexDocumentsClient { let documentsCount: number = 0; await this.client.documents.count({ ...updatedOptions, - onResponse: (response) => { - documentsCount = Number(response.bodyAsText); + onResponse: (rawResponse, flatResponse) => { + documentsCount = Number(rawResponse.bodyAsText); + if (updatedOptions.onResponse) { + updatedOptions.onResponse(rawResponse, flatResponse); + } }, }); @@ -516,8 +519,11 @@ export class SearchClient implements IndexDocumentsClient { { actions: serialize(batch.actions) }, { ...updatedOptions, - onResponse: (response) => { - status = response.status; + onResponse: (rawResponse, flatResponse) => { + status = rawResponse.status; + if (updatedOptions.onResponse) { + updatedOptions.onResponse(rawResponse, flatResponse); + } }, } );