Skip to content

Commit

Permalink
⚡ fix
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency committed Apr 17, 2024
1 parent 4c16000 commit 82c2594
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
16 changes: 16 additions & 0 deletions packages/nodes-base/nodes/Notion/shared/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
IHookFunctions,
IHttpRequestMethods,
ILoadOptionsFunctions,
INode,
INodeExecutionData,
INodeProperties,
IPairedItemData,
Expand All @@ -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;
Expand Down Expand Up @@ -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 });
};
39 changes: 22 additions & 17 deletions packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
notionApiRequest,
notionApiRequestAllItems,
notionApiRequestGetBlockChildrens,
prepareNotionError,
simplifyBlocksOutput,
simplifyObjects,
validateJSON,
Expand Down Expand Up @@ -91,7 +92,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -166,7 +167,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -198,7 +199,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -241,7 +242,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -304,7 +305,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -391,7 +392,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -421,7 +422,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -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 },
);
}
}

Expand Down Expand Up @@ -512,7 +517,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -564,7 +569,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand All @@ -590,7 +595,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -619,7 +624,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -653,7 +658,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -705,7 +710,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down Expand Up @@ -767,7 +772,7 @@ export class NotionV2 implements INodeType {
pairedItem: { item: i },
});
} else {
throw error;
throw prepareNotionError(this.getNode(), error, i);
}
}
}
Expand Down

0 comments on commit 82c2594

Please sign in to comment.