fix(Google Sheets Node): Check for null before destructuring (#7729)

https://n8nio.sentry.io/issues/4613453684
This commit is contained in:
Iván Ovejero 2023-11-16 16:50:06 +01:00 committed by GitHub
parent d39bb2540f
commit 5d4a52d3b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,12 @@ import { getSpreadsheetId } from '../helpers/GoogleSheets.utils';
import type { ResourceLocator } from '../helpers/GoogleSheets.types';
export async function getSheets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const { mode, value } = this.getNodeParameter('documentId', 0) as IDataObject;
const documentId = this.getNodeParameter('documentId', 0) as IDataObject | null;
if (!documentId) return [];
const { mode, value } = documentId;
const spreadsheetId = getSpreadsheetId(this.getNode(), mode as ResourceLocator, value as string);
const sheet = new GoogleSheet(spreadsheetId, this);
@ -33,7 +38,12 @@ export async function getSheets(this: ILoadOptionsFunctions): Promise<INodePrope
export async function getSheetHeaderRow(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const { mode, value } = this.getNodeParameter('documentId', 0) as IDataObject;
const documentId = this.getNodeParameter('documentId', 0) as IDataObject | null;
if (!documentId) return [];
const { mode, value } = documentId;
const spreadsheetId = getSpreadsheetId(this.getNode(), mode as ResourceLocator, value as string);
const sheet = new GoogleSheet(spreadsheetId, this);