-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Assign Unknown Error only if message or description not pr…
…esent in error
- Loading branch information
1 parent
deb4c04
commit 8aedc03
Showing
2 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { INode } from '../src/Interfaces'; | ||
import { NodeApiError } from '../src/NodeErrors'; | ||
|
||
const node: INode = { | ||
id: '1', | ||
name: 'Postgres node', | ||
typeVersion: 2, | ||
type: 'n8n-nodes-base.postgres', | ||
position: [60, 760], | ||
parameters: { | ||
operation: 'executeQuery', | ||
}, | ||
}; | ||
|
||
describe('NodeErrors tests', () => { | ||
it('should return unknown error message', () => { | ||
const nodeApiError = new NodeApiError(node, {}); | ||
|
||
expect(nodeApiError.message).toEqual( | ||
'UNKNOWN ERROR - check the detailed error for more information', | ||
); | ||
}); | ||
|
||
it('should return the error message', () => { | ||
const nodeApiError = new NodeApiError(node, { message: 'test error message' }); | ||
|
||
expect(nodeApiError.message).toEqual('test error message'); | ||
}); | ||
|
||
it('should return the error message defined in reason', () => { | ||
const nodeApiError = new NodeApiError(node, { reason: { message: 'test error message' } }); | ||
|
||
expect(nodeApiError.message).toEqual('test error message'); | ||
}); | ||
|
||
it('should return the error message defined in options', () => { | ||
const nodeApiError = new NodeApiError(node, {}, { message: 'test error message' }); | ||
|
||
expect(nodeApiError.message).toEqual('test error message'); | ||
}); | ||
|
||
it('should return description error message', () => { | ||
const nodeApiError = new NodeApiError(node, { description: 'test error description' }); | ||
|
||
expect(nodeApiError.message).toEqual('test error description'); | ||
}); | ||
|
||
it('should return description as error message defined in reason', () => { | ||
const nodeApiError = new NodeApiError(node, { | ||
reason: { description: 'test error description' }, | ||
}); | ||
|
||
expect(nodeApiError.message).toEqual('test error description'); | ||
}); | ||
|
||
it('should return description as error message defined in options', () => { | ||
const nodeApiError = new NodeApiError(node, {}, { description: 'test error description' }); | ||
|
||
expect(nodeApiError.message).toEqual('test error description'); | ||
}); | ||
|
||
it('should return default message for ECONNREFUSED', () => { | ||
const nodeApiError = new NodeApiError(node, { | ||
status: 'rejected', | ||
message: 'ECONNREFUSED', | ||
}); | ||
|
||
expect(nodeApiError.message).toEqual( | ||
'The service refused the connection - perhaps it is offline', | ||
); | ||
}); | ||
|
||
it('should return default message for 502', () => { | ||
const nodeApiError = new NodeApiError(node, { | ||
message: '502 Bad Gateway', | ||
}); | ||
|
||
expect(nodeApiError.message).toEqual('Bad gateway - the service failed to handle your request'); | ||
}); | ||
}); |