refactor(Google Sheets Node): Stop reporting to Sentry sheet not found error (no-changelog) (#7617)

https://n8nio.sentry.io/issues/4264383378
This commit is contained in:
Iván Ovejero 2023-11-06 11:36:22 +01:00 committed by GitHub
parent b11c4de039
commit 52f655f3d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 6 deletions

View file

@ -418,7 +418,10 @@ export class GoogleSheetsTrigger implements INodeType {
} }
const googleSheet = new GoogleSheet(documentId, this); 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 options = this.getNodeParameter('options') as IDataObject;
const previousRevision = workflowStaticData.lastRevision as number; const previousRevision = workflowStaticData.lastRevision as number;

View file

@ -51,7 +51,7 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
sheetName = `${spreadsheetId}||${sheetId}`; sheetName = `${spreadsheetId}||${sheetId}`;
break; break;
default: default:
sheetName = await googleSheet.spreadsheetGetSheetNameById(sheetId); sheetName = await googleSheet.spreadsheetGetSheetNameById(this.getNode(), sheetId);
} }
results = await sheet[googleSheets.operation].execute.call( results = await sheet[googleSheets.operation].execute.call(

View file

@ -3,6 +3,7 @@ import type {
ILoadOptionsFunctions, ILoadOptionsFunctions,
IDataObject, IDataObject,
IPollFunctions, IPollFunctions,
INode,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow'; import { NodeOperationError } from 'n8n-workflow';
import { utils as xlsxUtils } from 'xlsx'; import { utils as xlsxUtils } from 'xlsx';
@ -117,7 +118,7 @@ export class GoogleSheet {
/** /**
* Returns the name of a sheet from a sheet id * Returns the name of a sheet from a sheet id
*/ */
async spreadsheetGetSheetNameById(sheetId: string) { async spreadsheetGetSheetNameById(node: INode, sheetId: string) {
const query = { const query = {
fields: 'sheets.properties', fields: 'sheets.properties',
}; };
@ -133,9 +134,13 @@ export class GoogleSheet {
const foundItem = response.sheets.find( const foundItem = response.sheets.find(
(item: { properties: { sheetId: number } }) => item.properties.sheetId === +sheetId, (item: { properties: { sheetId: number } }) => item.properties.sheetId === +sheetId,
); );
if (!foundItem?.properties?.title) { 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; return foundItem.properties.title;
} }

View file

@ -45,7 +45,7 @@ export async function getSheetHeaderRow(
sheetWithinDocument = '0'; 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 sheetData = await sheet.getData(`${sheetName}!1:1`, 'FORMATTED_VALUE');
if (sheetData === undefined) { if (sheetData === undefined) {

View file

@ -23,7 +23,7 @@ export async function getMappingColumns(
sheetWithinDocument = '0'; 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 sheetData = await sheet.getData(`${sheetName}!1:1`, 'FORMATTED_VALUE');
const columns = sheet.testFilter(sheetData || [], 0, 0).filter((col) => col !== ''); const columns = sheet.testFilter(sheetData || [], 0, 0).filter((col) => col !== '');