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
Fixes #23709 - StatisticsCharts fails handling errors #5616
Conversation
Issues: #23709 |
2 similar comments
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.
looks good to me, but 1. I have now idea how it stopped working (could be axios pr related? @amirfefer ?) and wondering if we can add a test for it?
@ohadlevy Yes sure, I am working on this right now. |
@ohadlevy you're right: a5a6b5d#diff-0be26feab8a96771c4d11efe9e3758c1L13. In regards to why tests pass - we don't have tests to Anyway, this patch fixes all these regressions - adding more tests and fixing some (due to moving to axios) . Thanks for the information Ohad. |
@@ -11,5 +11,5 @@ export const ajaxRequestAction = ({ | |||
dispatch({ type: requestAction, payload: item }); | |||
return API.get(url) | |||
.then(({ data }) => dispatch({ type: successAction, payload: { ...item, ...data } })) | |||
.catch(error => dispatch({ type: failedAction, payload: { error, item } })); | |||
.catch(error => dispatch({ type: failedAction, payload: { item, error: error.message } })); |
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.
does it work with all the components that use ajaxRequestAction
?
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.
Yes, it does. I did do manual testing if that helps.
Basically, there are 4 components that are doing API calls:
BreadcrumbBar, Bookmarks, Host's PowerStatus and Statistics.
3 out of them are using ajaxRequestAction
- BreadcrumbBar doesn't use ajaxRequestAction
probably because of payload
structure nuance.
Bookmarks doesn't use any element set in item
but does expect error
to be the error message - which is fixed in this patch.
Host's PowerStatus and Statistics however are expecting the payload to have id
given in item
(I guess matan
missed that change when he pushed this) so I decided to keep item
there and use it in reducers.
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.
I guess it would be nicer if I keep the order, though (for a readable diff):
payload: { error: error.message, item }
@@ -32,7 +32,7 @@ class StatisticsChartsList extends React.Component { | |||
chart={chart} | |||
noDataMsg={__('No data available')} | |||
tip={__('Expand the chart')} | |||
errorText={chart.error} | |||
errorText={chart.error ? chart.error.message : ''} |
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.
Forgot to discard this change, though.
@@ -11,5 +11,5 @@ export const ajaxRequestAction = ({ | |||
dispatch({ type: requestAction, payload: item }); | |||
return API.get(url) | |||
.then(({ data }) => dispatch({ type: successAction, payload: { ...item, ...data } })) | |||
.catch(error => dispatch({ type: failedAction, payload: { error, item } })); | |||
.catch(error => dispatch({ type: failedAction, payload: { error: error.message, item } })); |
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.
I have one concern about storing only the error message:
the message property is optional, and could be blank, plus if we'd like to distinct between error types we couldn't do it only with the error's message.
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.
No problem. We can keep storing the error
object but will map from error
object to error
message on the component side.
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.
Thanks @ripcurld looks good !
I left some minor inline comments
Next time just please add a comment after an update :)
@@ -27,4 +27,3 @@ export const onSuccessActions = | |||
payload: mockSuccessRequests[0].response, | |||
type: 'HOST_POWER_STATUS_SUCCESS', | |||
}; | |||
|
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.
unnecessary deletion
prev: stateBeforeResponse, | ||
action: { | ||
type: types.HOST_POWER_STATUS_FAILURE, | ||
payload: { error, item: { id: request.id } }, |
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.
could we store the entire resource under item ?
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.
By saying "entire resource" are you talking about the request
?
Basically you want to change this line to
payload: { error, item: request }
Right?
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.
After a second look, only the id is stored via ajaxRequestAction
'should return the initial state': { | ||
prev: undefined, | ||
action: {}, | ||
next: initialState, |
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.
I personally prefer snapshots rather then supply a preconfigured results object.
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.
I will see what I can do about that.
@sharvit @amirfefer |
@@ -32,7 +32,7 @@ class StatisticsChartsList extends React.Component { | |||
chart={chart} | |||
noDataMsg={__('No data available')} | |||
tip={__('Expand the chart')} | |||
errorText={chart.error} | |||
errorText={(chart.error || {}).message ? chart.error.message : ''} |
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.
could errorText
remain undefined instead of initialize empty string each render?
errorText={chart.error && chart.error.message}
The FAILURE action dispatched in ajaxRequestAction is not aligned with the bookmarks, powerStatus and statistics reducers: - Moving to axios returns Error object instead of a string - The payload doesn't contain "id" but "item" This patch fixes that problem and makes components work on failures from API. In addition, tests were added and fixed to avoid regressions. Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
[test katello] |
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.
LGTM 👍
[test katello] |
test failure unrelated. thanks @ripcurld |
/cc @ohadlevy @amirfefer @sharvit
It seems like when an error occures during fetching the data the error object is not passed to
ChartBox
as a string.In addition, the action payload is different when error occures, causing the error message to be in a new
ChartBox
.Before
After