-
-
Notifications
You must be signed in to change notification settings - Fork 24.5k
fix(ui): guard missing Axios error.response in ToolDialog error handlers #6482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chatman-media
wants to merge
2
commits into
FlowiseAI:main
Choose a base branch
from
chatman-media:fix/axios-error-response-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,64 @@ | ||
| import { getErrorMessage, getAxiosErrorMessage } from './errorHandler' | ||
|
|
||
| describe('getErrorMessage', () => { | ||
| it('returns the message from an Error object', () => { | ||
| expect(getErrorMessage(new Error('boom'))).toBe('boom') | ||
| }) | ||
|
|
||
| it('serialises a plain object when it has no message property', () => { | ||
| const result = getErrorMessage({ code: 42 }) | ||
| expect(result).toContain('42') | ||
| }) | ||
| }) | ||
|
|
||
| describe('getAxiosErrorMessage', () => { | ||
| it('returns a safe fallback when error.response is undefined (network failure / timeout / CORS)', () => { | ||
| const axiosNetworkError = new Error('Network Error') | ||
| // Axios sets no .response on network-level failures | ||
| expect(axiosNetworkError.response).toBeUndefined() | ||
| expect(getAxiosErrorMessage(axiosNetworkError)).toBe('Network Error') | ||
| }) | ||
|
|
||
| it('returns a safe fallback when the error itself is undefined', () => { | ||
| expect(getAxiosErrorMessage(undefined)).toBe('An unexpected error occurred') | ||
| }) | ||
|
|
||
| it('returns a safe fallback when the error is null', () => { | ||
| expect(getAxiosErrorMessage(null)).toBe('An unexpected error occurred') | ||
| }) | ||
|
|
||
| it('extracts response.data.message when the server returns a structured error', () => { | ||
| const error = { response: { data: { message: 'Validation failed', code: 400 } } } | ||
| expect(getAxiosErrorMessage(error)).toBe('Validation failed') | ||
| }) | ||
|
|
||
| it('extracts response.data.error when only that key is present', () => { | ||
| const error = { response: { data: { error: 'Unauthorized' } } } | ||
| expect(getAxiosErrorMessage(error)).toBe('Unauthorized') | ||
| }) | ||
|
|
||
| it('resolves a nested error object ({ error: { message } }) to its message', () => { | ||
| const error = { response: { data: { error: { message: 'Nested failure' } } } } | ||
| expect(getAxiosErrorMessage(error)).toBe('Nested failure') | ||
| }) | ||
|
|
||
| it('joins an array of messages (NestJS validation) into a single string', () => { | ||
| const error = { response: { data: { message: ['name is required', 'email is invalid'] } } } | ||
| expect(getAxiosErrorMessage(error)).toBe('name is required, email is invalid') | ||
| }) | ||
|
|
||
| it('returns a plain string response body as-is', () => { | ||
| const error = { response: { data: 'Internal Server Error' } } | ||
| expect(getAxiosErrorMessage(error)).toBe('Internal Server Error') | ||
| }) | ||
|
|
||
| it('falls back to error.message when response.data is falsy', () => { | ||
| const error = { response: { data: null }, message: 'Request failed with status 503' } | ||
| expect(getAxiosErrorMessage(error)).toBe('Request failed with status 503') | ||
| }) | ||
|
|
||
| it('returns the generic fallback when there is no message at all', () => { | ||
| const error = {} | ||
| expect(getAxiosErrorMessage(error)).toBe('An unexpected error occurred') | ||
| }) | ||
| }) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the API returns a nested error object (e.g.,
{ error: { message: '...' } }which is common in OpenAI and other standard APIs) or an array of messages (e.g.,['error 1', 'error 2']in NestJS validation errors), the current implementation will return the object or array directly. When interpolated into a string in the UI, this results in[object Object]or unformatted output.We can make
getAxiosErrorMessagemore robust by safely resolving nested error objects and joining array messages with commas.References