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,
IHttpRequestMethods,
ILoadOptionsFunctions,
INode,
INodeExecutionData,
INodeProperties,
IPairedItemData,
@ -21,6 +22,7 @@ import moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid';
import { filters } from './descriptions/Filters';
import set from 'lodash/set';
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
if (uuidValidate(value)) return true;
@ -1170,3 +1172,17 @@ export function extractBlockId(this: IExecuteFunctions, nodeVersion: number, ite
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,
notionApiRequestAllItems,
notionApiRequestGetBlockChildrens,
prepareNotionError,
simplifyBlocksOutput,
simplifyObjects,
validateJSON,
@ -91,7 +92,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -166,7 +167,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -198,7 +199,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -241,7 +242,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -304,7 +305,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -391,7 +392,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -421,7 +422,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -459,9 +460,13 @@ export class NotionV2 implements INodeType {
if (validateJSON(filterJson) !== undefined) {
body.filter = jsonParse(filterJson);
} else {
throw new NodeApiError(this.getNode(), {
message: 'Filters (JSON) must be a valid json',
});
throw new NodeApiError(
this.getNode(),
{
message: 'Filters (JSON) must be a valid json',
},
{ itemIndex: i },
);
}
}
@ -512,7 +517,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -564,7 +569,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -590,7 +595,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -619,7 +624,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -653,7 +658,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -705,7 +710,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
@ -767,7 +772,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}