For the complete documentation index, see llms.txt. This page is also available as Markdown.

Error handling

Proper error handling is crucial for creating robust n8n nodes that provide clear feedback to users when things go wrong. n8n provides two specialized error classes to handle different types of failures in node implementations:

  • NodeApiError: For API-related errors and external service failures

  • NodeOperationError: For operational errors, validation failures, and configuration issues

NodeApiError

Use NodeApiError when dealing with external API calls and HTTP requests. This error class is specifically designed to handle API response errors and provides enhanced features for parsing and presenting API-related failures such as:

  • HTTP request failures

  • external API errors

  • authentication/authorization failures

  • rate limiting errors

  • service unavailable errors

Initialize new NodeApiError instances using the following pattern:

new NodeApiError(node: INode, errorResponse: JsonObject, options?: NodeApiErrorOptions)

Common usage patterns

For basic API request failures, catch the error and wrap it in NodeApiError:

try {
	const response = await this.helpers.httpRequestWithAuthentication.call(
		this,
		credentialType,
		options
	);
	return response;
} catch (error) {
	throw new NodeApiError(this.getNode(), error as JsonObject);
}

Handle specific HTTP status codes with custom messages:

NodeOperationError

Use NodeOperationError for:

  • operational errors

  • validation failures

  • configuration issues that aren't related to external API calls

  • input validation errors

  • missing required parameters

  • data transformation errors

  • workflow logic errors

Initialize new NodeOperationError instances using the following pattern:

Common usage patterns

Use NodeOperationError for validating user inputs:

When processing multiple items, include the item index for better error context:

Last updated

Was this helpful?