mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Descriptive message for common nodeJS errors (#6841)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { INode } from '../src/Interfaces';
|
||||
import { NodeApiError } from '../src/NodeErrors';
|
||||
import { NodeApiError, NodeOperationError } from '../src/NodeErrors';
|
||||
|
||||
const node: INode = {
|
||||
id: '1',
|
||||
@@ -76,4 +76,101 @@ describe('NodeErrors tests', () => {
|
||||
|
||||
expect(nodeApiError.message).toEqual('Bad gateway - the service failed to handle your request');
|
||||
});
|
||||
|
||||
it('should return default message for ENOTFOUND, NodeOperationError', () => {
|
||||
const nodeOperationError = new NodeOperationError(node, 'ENOTFOUND test error message');
|
||||
|
||||
expect(nodeOperationError.message).toEqual(
|
||||
'The connection cannot be established, this usually occurs due to an incorrect host(domain) value',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return default message for ENOTFOUND, NodeApiError', () => {
|
||||
const nodeApiError = new NodeApiError(node, { message: 'ENOTFOUND test error message' });
|
||||
|
||||
expect(nodeApiError.message).toEqual(
|
||||
'The connection cannot be established, this usually occurs due to an incorrect host(domain) value',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return default message for EEXIST based on code, NodeApiError', () => {
|
||||
const nodeApiError = new NodeApiError(node, {
|
||||
message: 'test error message',
|
||||
code: 'EEXIST',
|
||||
});
|
||||
|
||||
expect(nodeApiError.message).toEqual('The file or directory already exists');
|
||||
});
|
||||
|
||||
it('should update description GETADDRINFO, NodeOperationError', () => {
|
||||
const nodeOperationError = new NodeOperationError(node, 'GETADDRINFO test error message', {
|
||||
description: 'test error description',
|
||||
});
|
||||
|
||||
expect(nodeOperationError.message).toEqual('The server closed the connection unexpectedly');
|
||||
|
||||
expect(nodeOperationError.description).toEqual(
|
||||
'GETADDRINFO test error message - test error description',
|
||||
);
|
||||
});
|
||||
|
||||
it('should remove description if it is equal to message, NodeOperationError', () => {
|
||||
const nodeOperationError = new NodeOperationError(node, 'some text', {
|
||||
description: 'some text',
|
||||
});
|
||||
|
||||
expect(nodeOperationError.message).toEqual('some text');
|
||||
|
||||
expect(nodeOperationError.description).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('should remove description if it is equal to message, message provided in options take precedence over original, NodeApiError', () => {
|
||||
const nodeApiError = new NodeApiError(
|
||||
node,
|
||||
{
|
||||
message: 'original message',
|
||||
},
|
||||
{ message: 'new text', description: 'new text' },
|
||||
);
|
||||
|
||||
expect(nodeApiError.message).toEqual('new text');
|
||||
|
||||
expect(nodeApiError.description).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('should return mapped message for MYMAPPEDMESSAGE, NodeOperationError', () => {
|
||||
const nodeOperationError = new NodeOperationError(node, 'MYMAPPEDMESSAGE test error message', {
|
||||
messageMapping: {
|
||||
MYMAPPEDMESSAGE: 'test error message',
|
||||
},
|
||||
});
|
||||
|
||||
expect(nodeOperationError.message).toEqual('test error message');
|
||||
});
|
||||
|
||||
it('should return mapped message for MYMAPPEDMESSAGE, NodeApiError', () => {
|
||||
const nodeApiError = new NodeApiError(
|
||||
node,
|
||||
{ message: 'MYMAPPEDMESSAGE test error message' },
|
||||
{
|
||||
messageMapping: {
|
||||
MYMAPPEDMESSAGE: 'test error message',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(nodeApiError.message).toEqual('test error message');
|
||||
});
|
||||
|
||||
it('should return default message for EACCES, custom mapping not found, NodeOperationError', () => {
|
||||
const nodeOperationError = new NodeOperationError(node, 'EACCES test error message', {
|
||||
messageMapping: {
|
||||
MYMAPPEDMESSAGE: 'test error message',
|
||||
},
|
||||
});
|
||||
|
||||
expect(nodeOperationError.message).toEqual(
|
||||
'Forbidden by access permissions, make sure you have the right permissions',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user