Skip to content

Commit 153b4b7

Browse files
committed
refactor(retail): improve error logging in search samples
Standardized catch block messages and updated console.error to use comma-separated arguments with error.message || error for better visibility.
1 parent d844a3f commit 153b4b7

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

retail/snippets/searchOffset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function searchOffset(projectId, placementId, visitorId, query, offset) {
6363
console.log(`Scores: ${JSON.stringify(result.modelScores || {})}`);
6464
}
6565
} catch (error) {
66-
console.error(`Error searching using offset: ${error.message}`);
66+
console.error('Error searching using offset:', error.message || error);
6767
}
6868
}
6969

retail/snippets/searchPagination.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ async function searchPagination(projectId, placementId, visitorId, query) {
9090
console.log('No more pages.');
9191
}
9292
} catch (error) {
93-
console.error('Failed to complete paginated search:', error);
93+
console.error(
94+
'Failed to complete paginated search:',
95+
error.message || error
96+
);
9497
}
9598
}
9699
// [END retail_v2_search_pagination]

retail/snippets/searchRequest.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
'use strict';
16+
1517
// [START retail_v2_search_request]
1618
const {SearchServiceClient} = require('@google-cloud/retail');
1719

@@ -65,11 +67,11 @@ async function searchRequest(
6567
console.log('--- Search Results ---');
6668
for (const result of results) {
6769
console.log(`Product ID: ${result.id}`);
68-
console.log(` Name: ${result.product.name}`);
69-
console.log(` Scores: ${JSON.stringify(result.modelScores || {})}`);
70+
console.log(`Title: ${result.product.title}`);
71+
console.log(`Scores: ${JSON.stringify(result.modelScores || {})}`);
7072
}
7173
} catch (error) {
72-
console.error(`Operation failed: ${error.message}`);
74+
console.error('Error executing search request:', error.message || error);
7375
}
7476
}
7577

0 commit comments

Comments
 (0)