Skip to content

Commit

Permalink
refactor(Google Sheets Node): Stop reporting to Sentry sheet not foun…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Nov 6, 2023
1 parent b11c4de commit 52f655f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ export class GoogleSheetsTrigger implements INodeType {
}

const googleSheet = new GoogleSheet(documentId, this);
const sheetName: string = await googleSheet.spreadsheetGetSheetNameById(sheetId);
const sheetName: string = await googleSheet.spreadsheetGetSheetNameById(
this.getNode(),
sheetId,
);
const options = this.getNodeParameter('options') as IDataObject;

const previousRevision = workflowStaticData.lastRevision as number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
sheetName = `${spreadsheetId}||${sheetId}`;
break;
default:
sheetName = await googleSheet.spreadsheetGetSheetNameById(sheetId);
sheetName = await googleSheet.spreadsheetGetSheetNameById(this.getNode(), sheetId);
}

results = await sheet[googleSheets.operation].execute.call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ILoadOptionsFunctions,
IDataObject,
IPollFunctions,
INode,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { utils as xlsxUtils } from 'xlsx';
Expand Down Expand Up @@ -117,7 +118,7 @@ export class GoogleSheet {
/**
* Returns the name of a sheet from a sheet id
*/
async spreadsheetGetSheetNameById(sheetId: string) {
async spreadsheetGetSheetNameById(node: INode, sheetId: string) {
const query = {
fields: 'sheets.properties',
};
Expand All @@ -133,9 +134,13 @@ export class GoogleSheet {
const foundItem = response.sheets.find(
(item: { properties: { sheetId: number } }) => item.properties.sheetId === +sheetId,
);

if (!foundItem?.properties?.title) {
throw new Error(`Sheet with id ${sheetId} not found`);
throw new NodeOperationError(node, `Sheet with ID ${sheetId} not found`, {
severity: 'warning',
});
}

return foundItem.properties.title;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function getSheetHeaderRow(
sheetWithinDocument = '0';
}

const sheetName = await sheet.spreadsheetGetSheetNameById(sheetWithinDocument);
const sheetName = await sheet.spreadsheetGetSheetNameById(this.getNode(), sheetWithinDocument);
const sheetData = await sheet.getData(`${sheetName}!1:1`, 'FORMATTED_VALUE');

if (sheetData === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getMappingColumns(
sheetWithinDocument = '0';
}

const sheetName = await sheet.spreadsheetGetSheetNameById(sheetWithinDocument);
const sheetName = await sheet.spreadsheetGetSheetNameById(this.getNode(), sheetWithinDocument);
const sheetData = await sheet.getData(`${sheetName}!1:1`, 'FORMATTED_VALUE');

const columns = sheet.testFilter(sheetData || [], 0, 0).filter((col) => col !== '');
Expand Down

0 comments on commit 52f655f

Please sign in to comment.