Refactor Salesforce Query Logging and Error Handling
- Removed detailed logging of Salesforce query execution to streamline the process. - Simplified error handling by logging only the error message instead of the full context and SOQL query. - Enhanced readability and maintainability of the BaseServicesService class by reducing unnecessary log statements.
This commit is contained in:
parent
1b944f57aa
commit
9b1e93b7cb
@ -39,32 +39,15 @@ export class BaseServicesService {
|
||||
soql: string,
|
||||
context: string
|
||||
): Promise<TRecord[]> {
|
||||
this.logger.debug(`Executing Salesforce query for ${context}`, {
|
||||
soql: soql.replace(/\s+/g, " ").trim(),
|
||||
portalPricebookId: this.portalPriceBookId,
|
||||
portalCategoryField: this.portalCategoryField,
|
||||
});
|
||||
|
||||
try {
|
||||
const res = (await this.sf.query(soql, {
|
||||
label: `services:${context.replace(/\s+/g, "_").toLowerCase()}`,
|
||||
})) as SalesforceResponse<TRecord>;
|
||||
const records = res.records ?? [];
|
||||
this.logger.debug(`Query result for ${context}`, {
|
||||
recordCount: records.length,
|
||||
records: records.map(r => ({
|
||||
id: r.Id,
|
||||
name: r.Name,
|
||||
sku: r.StockKeepingUnit,
|
||||
itemClass: r.Item_Class__c,
|
||||
hasPricebookEntries: Boolean(r.PricebookEntries?.records?.length),
|
||||
})),
|
||||
});
|
||||
return records;
|
||||
return res.records ?? [];
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = getErrorMessage(error);
|
||||
this.logger.error(`Query failed: ${context} - ${errorMessage}`);
|
||||
this.logger.error(`Failed SOQL: ${soql.replace(/\s+/g, " ").trim()}`);
|
||||
this.logger.error(`Query failed: ${context}`, {
|
||||
error: getErrorMessage(error),
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user