Skip to content

Commit cf7f276

Browse files
feat: add itemIndex and description to thrown errors to provide context
1 parent c3d5181 commit cf7f276

File tree

9 files changed

+206
-93
lines changed

9 files changed

+206
-93
lines changed

nodes/ZeroBounce/ZeroBounce.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class ZeroBounce implements INodeType {
121121
try {
122122
const resource = this.getNodeParameter('resource', itemIndex);
123123
const operation = this.getNodeParameter('operation', itemIndex);
124-
const operationHandler = getHandler(this, handlers, resource);
124+
const operationHandler = getHandler(this, itemIndex, handlers, resource);
125125

126126
const responseData = await operationHandler.handle(this, operation, itemIndex);
127127

nodes/ZeroBounce/fields/activity-data.field.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const ActivityData: INodeProperties = {
77
name: Fields.ActivityData,
88
type: 'boolean',
99
default: false,
10-
placeholder: 'false',
1110
noDataExpression: true,
1211
description: 'Whether Activity Data information will be appended to the validation result',
1312
};

nodes/ZeroBounce/handlers/account.handler.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { IRequestParams, zbGetRequest, zbPostRequest } from '../utils/request.utils';
22
import {
3+
getDateParameter,
34
getNumberParameter,
45
IAltErrorResponse,
56
IErrorResponse,
67
IOperationHandler,
78
isAltErrorResponse,
89
isErrorResponse,
9-
toDate,
1010
} from '../utils/handler.utils';
1111
import { IDataObject, IExecuteFunctions, INodeExecutionData, NodeOperationError } from 'n8n-workflow';
1212
import { BaseUrl, Endpoint, Operations } from '../enums';
@@ -81,7 +81,7 @@ interface IDeleteFilterResponse extends IDataObject {
8181
*/
8282
async function getCredits(context: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
8383
const baseUrl = context.getNodeParameter(ApiEndpoint.name, i) as BaseUrl;
84-
const creditsRequired = getNumberParameter(context, i, CreditsRequired.name, 0);
84+
const creditsRequired = getNumberParameter(context, i, CreditsRequired, 0);
8585

8686
const fullResponse = await zbGetRequest(context, baseUrl, Endpoint.GetCredits);
8787
const response = fullResponse.body as IGetCreditsResponse | IErrorResponse;
@@ -127,13 +127,11 @@ async function getCredits(context: IExecuteFunctions, i: number): Promise<INodeE
127127
* Dates are normalized to ISO yyyy-mm-dd.
128128
*/
129129
async function getApiUsage(context: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
130-
const startDate = context.getNodeParameter(StartDate.name, i) as string;
131-
const endDate = context.getNodeParameter(EndDate.name, i) as string;
132130
const baseUrl = context.getNodeParameter(ApiEndpoint.name, i) as BaseUrl;
133131

134132
const request = {
135-
start_date: toDate(context, startDate),
136-
end_date: toDate(context, endDate),
133+
start_date: getDateParameter(context, i, StartDate),
134+
end_date: getDateParameter(context, i, EndDate),
137135
} as IGetApiUsageRequest;
138136

139137
const fullResponse = await zbGetRequest(context, baseUrl, Endpoint.GetApiUsage, request);
@@ -225,7 +223,10 @@ class AccountHandler implements IOperationHandler {
225223
case Operations.AccountDeleteFilter:
226224
return addOrDeleteFilter(context, i, AddOrDelete.DELETE);
227225
default:
228-
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`);
226+
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`, {
227+
itemIndex: i,
228+
description: 'Please select an operation from the list',
229+
});
229230
}
230231
}
231232
}

nodes/ZeroBounce/handlers/domain-search.handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export class DomainSearchHandler implements IOperationHandler {
1818
case Operations.BulkDomainSearchDeleteFile:
1919
return deleteFile(context, i, Mode.DOMAIN_SEARCH);
2020
default:
21-
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`);
21+
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`, {
22+
itemIndex: i,
23+
description: 'Please select an operation from the list',
24+
});
2225
}
2326
}
2427
}

nodes/ZeroBounce/handlers/email-finder.handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export class EmailFinderHandler implements IOperationHandler {
1818
case Operations.BulkEmailFinderDeleteFile:
1919
return deleteFile(context, i, Mode.EMAIL_FINDER);
2020
default:
21-
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`);
21+
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`, {
22+
itemIndex: i,
23+
description: 'Please select an operation from the list',
24+
});
2225
}
2326
}
2427
}

nodes/ZeroBounce/handlers/scoring.handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export class ScoringHandler implements IOperationHandler {
5252
case Operations.BulkScoringDeleteFile:
5353
return deleteFile(context, i, Mode.SCORING);
5454
default:
55-
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`);
55+
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`, {
56+
itemIndex: i,
57+
description: 'Please select an operation from the list',
58+
});
5659
}
5760
}
5861
}

nodes/ZeroBounce/handlers/validation.handler.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ interface IValidateBatchResult extends IDataObject {
106106
* - Handles all request construction and response parsing internally.
107107
*/
108108
async function validate(context: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
109-
const timeout = getNumberParameter(context, i, Timeout.name);
109+
const timeout = getNumberParameter(context, i, Timeout);
110110
const activityData = context.getNodeParameter(ActivityData.name, i, false, { ensureType: 'boolean' }) as boolean;
111111
const verifyPlus = context.getNodeParameter(VerifyPlus.name, i, false, { ensureType: 'boolean' }) as boolean;
112112
const email = context.getNodeParameter(Email.name, i) as string;
@@ -174,7 +174,7 @@ async function validate(context: IExecuteFunctions, i: number): Promise<INodeExe
174174
* - The function wraps the ZeroBounce response in an n8n `INodeExecutionData` structure for workflow compatibility.
175175
*/
176176
async function batchValidate(context: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
177-
const timeout = getNumberParameter(context, i, Timeout.name);
177+
const timeout = getNumberParameter(context, i, Timeout);
178178
const activityData = context.getNodeParameter(ActivityData.name, i, false, { ensureType: 'boolean' }) as boolean;
179179
const verifyPlus = context.getNodeParameter(VerifyPlus.name, i, false, { ensureType: 'boolean' }) as boolean;
180180
const emailBatch = convertItemInput(context, i, Mode.VALIDATION) as IEmailEntry[];
@@ -225,7 +225,10 @@ export class ValidationHandler implements IOperationHandler {
225225
case Operations.BulkValidationDeleteFile:
226226
return deleteFile(context, i, Mode.VALIDATION);
227227
default:
228-
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`);
228+
throw new NodeOperationError(context.getNode(), `Operation ${operation} not supported`, {
229+
itemIndex: i,
230+
description: 'Please select an operation from the list',
231+
});
229232
}
230233
}
231234
}

nodes/ZeroBounce/utils/finder.utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ export async function find(context: IExecuteFunctions, i: number, mode: Mode): P
8989
const lastName = context.getNodeParameter(LastName.name, i) as string | undefined;
9090

9191
if (isBlank(firstName) && isBlank(lastName)) {
92-
throw new NodeOperationError(context.getNode(), 'Email Finder at least first name or last name to be set');
92+
throw new NodeOperationError(
93+
context.getNode(),
94+
`Email Finder requires '${FirstName.displayName}' or '${LastName.displayName}'`,
95+
{
96+
itemIndex: i,
97+
description: `Enter a value for '${FirstName.displayName}', '${LastName.displayName}' or both`,
98+
},
99+
);
93100
}
94101

95102
request = {

0 commit comments

Comments
 (0)