Package version (if known): latest
Describe the bug
Bug: Server error responses (500) cause malformed Redux state due to missing error validation
Description
When the server returns a 500 error (or other non-JSON responses like HTML error pages), the error handling in deposit actions and reducer does not validate the structure of error.errors, leading to corrupted Redux state.
Problem
1. In the actions file, multiple catch blocks dispatch error.errors without validation:
2. In the reducer, errors are spread into an object without type checking:
What happens
When a 500 error occurs, the server returns an HTML error page instead of JSON. This results in error.errors being undefined or a string containing HTML.
When a string is spread into an object, JavaScript creates an object with numeric indices as keys and individual characters as values:
{ ..."<html>" }
// Results in: { '0': '<', '1': 'h', '2': 't', '3': 'm', '4': 'l', '5': '>' }
This corrupts the Redux errors state, making it unusable for error display.
Expected behavior
Error responses should be validated before being stored in Redux state. Non-structured errors should be normalized to a consistent format.
Suggested fix
Add error normalization before dispatching:
const normalizeErrors = (error) => {
if (error.errors && typeof error.errors === 'object') {
return error.errors;
}
const message = error.response?.data?.message
|| error.message
|| 'An unexpected server error occurred';
return { message };
};
Steps to Reproduce
If you get a 500 error while making actions from the form, you get html returned.
Expected behavior
Package version (if known): latest
Describe the bug
Bug: Server error responses (500) cause malformed Redux state due to missing error validation
Description
When the server returns a 500 error (or other non-JSON responses like HTML error pages), the error handling in deposit actions and reducer does not validate the structure of
error.errors, leading to corrupted Redux state.Problem
1. In the actions file, multiple catch blocks dispatch
error.errorswithout validation:_saveDraft- Line 97publish- Line 219submitReview- Line 257delete_- Line 306reservePID- Line 336discardPID- Line 3662. In the reducer, errors are spread into an object without type checking:
What happens
When a 500 error occurs, the server returns an HTML error page instead of JSON. This results in
error.errorsbeingundefinedor a string containing HTML.When a string is spread into an object, JavaScript creates an object with numeric indices as keys and individual characters as values:
This corrupts the Redux
errorsstate, making it unusable for error display.Expected behavior
Error responses should be validated before being stored in Redux state. Non-structured errors should be normalized to a consistent format.
Suggested fix
Add error normalization before dispatching:
Steps to Reproduce
If you get a 500 error while making actions from the form, you get html returned.
Expected behavior