forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Improve model sub-nodes error handling (n8n-io#11418)
- Loading branch information
1 parent
b496bf3
commit 57467d0
Showing
24 changed files
with
309 additions
and
55 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
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
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
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
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
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
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
66 changes: 66 additions & 0 deletions
66
packages/@n8n/nodes-langchain/nodes/llms/n8nDefaultFailedAttemptHandler.test.ts
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,66 @@ | ||
import { n8nDefaultFailedAttemptHandler } from './n8nDefaultFailedAttemptHandler'; | ||
|
||
class MockHttpError extends Error { | ||
response: { status: number }; | ||
|
||
constructor(message: string, code: number) { | ||
super(message); | ||
this.response = { status: code }; | ||
} | ||
} | ||
|
||
describe('n8nDefaultFailedAttemptHandler', () => { | ||
it('should throw error if message starts with "Cancel"', () => { | ||
const error = new Error('Cancel operation'); | ||
expect(() => n8nDefaultFailedAttemptHandler(error)).toThrow(error); | ||
}); | ||
|
||
it('should throw error if message starts with "AbortError"', () => { | ||
const error = new Error('AbortError occurred'); | ||
expect(() => n8nDefaultFailedAttemptHandler(error)).toThrow(error); | ||
}); | ||
|
||
it('should throw error if name is "AbortError"', () => { | ||
class MockAbortError extends Error { | ||
constructor() { | ||
super('Some error'); | ||
this.name = 'AbortError'; | ||
} | ||
} | ||
|
||
const error = new MockAbortError(); | ||
|
||
expect(() => n8nDefaultFailedAttemptHandler(error)).toThrow(error); | ||
}); | ||
|
||
it('should throw error if code is "ECONNABORTED"', () => { | ||
class MockAbortError extends Error { | ||
code: string; | ||
|
||
constructor() { | ||
super('Some error'); | ||
this.code = 'ECONNABORTED'; | ||
} | ||
} | ||
|
||
const error = new MockAbortError(); | ||
expect(() => n8nDefaultFailedAttemptHandler(error)).toThrow(error); | ||
}); | ||
|
||
it('should throw error if status is in STATUS_NO_RETRY', () => { | ||
const error = new MockHttpError('Some error', 400); | ||
expect(() => n8nDefaultFailedAttemptHandler(error)).toThrow(error); | ||
}); | ||
|
||
it('should not throw error if status is not in STATUS_NO_RETRY', () => { | ||
const error = new MockHttpError('Some error', 500); | ||
error.response = { status: 500 }; | ||
|
||
expect(() => n8nDefaultFailedAttemptHandler(error)).not.toThrow(); | ||
}); | ||
|
||
it('should not throw error if no conditions are met', () => { | ||
const error = new Error('Some random error'); | ||
expect(() => n8nDefaultFailedAttemptHandler(error)).not.toThrow(); | ||
}); | ||
}); |
Oops, something went wrong.