fix(Notion Node): Add itemIndex to API and operation errors (#9150)

This commit is contained in:
Michael Kret 2024-04-17 14:51:34 +03:00 committed by GitHub
parent ac4577f78a
commit 946f09f628
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 17 deletions

View file

@ -6,6 +6,7 @@ import type {
IHookFunctions, IHookFunctions,
IHttpRequestMethods, IHttpRequestMethods,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INode,
INodeExecutionData, INodeExecutionData,
INodeProperties, INodeProperties,
IPairedItemData, IPairedItemData,
@ -21,6 +22,7 @@ import moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid'; import { validate as uuidValidate } from 'uuid';
import { filters } from './descriptions/Filters'; import { filters } from './descriptions/Filters';
import set from 'lodash/set';
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) { function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
if (uuidValidate(value)) return true; if (uuidValidate(value)) return true;
@ -1170,3 +1172,17 @@ export function extractBlockId(this: IExecuteFunctions, nodeVersion: number, ite
return blockId; return blockId;
} }
export const prepareNotionError = (node: INode, error: Error, itemIndex: number) => {
if (error instanceof NodeApiError) {
set(error, 'context.itemIndex', itemIndex);
return error;
}
if (error instanceof NodeOperationError && error?.context?.itemIndex === undefined) {
set(error, 'context.itemIndex', itemIndex);
return error;
}
return new NodeOperationError(node, error, { itemIndex });
};

View file

@ -23,6 +23,7 @@ import {
notionApiRequest, notionApiRequest,
notionApiRequestAllItems, notionApiRequestAllItems,
notionApiRequestGetBlockChildrens, notionApiRequestGetBlockChildrens,
prepareNotionError,
simplifyBlocksOutput, simplifyBlocksOutput,
simplifyObjects, simplifyObjects,
validateJSON, validateJSON,
@ -91,7 +92,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -166,7 +167,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -198,7 +199,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -241,7 +242,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -304,7 +305,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -391,7 +392,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -421,7 +422,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -459,9 +460,13 @@ export class NotionV2 implements INodeType {
if (validateJSON(filterJson) !== undefined) { if (validateJSON(filterJson) !== undefined) {
body.filter = jsonParse(filterJson); body.filter = jsonParse(filterJson);
} else { } else {
throw new NodeApiError(this.getNode(), { throw new NodeApiError(
message: 'Filters (JSON) must be a valid json', this.getNode(),
}); {
message: 'Filters (JSON) must be a valid json',
},
{ itemIndex: i },
);
} }
} }
@ -512,7 +517,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -564,7 +569,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -590,7 +595,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -619,7 +624,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -653,7 +658,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -705,7 +710,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }
@ -767,7 +772,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i }, pairedItem: { item: i },
}); });
} else { } else {
throw error; throw prepareNotionError(this.getNode(), error, i);
} }
} }
} }