mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
* consistent error handling * Display server errors in InviteUserForm * Handle errors in Form component * Refactors query form * creates KolideAce component * Renders QueryForm from query page and manage hosts page * Moves ace editor and select targets dropdown to query form * Render base errors in Form HOC * LoginPage and ForgotPasswordPage server errors * Ensure unique key for user blocks * Adds base error to login form and forgot password form * Adds base error to query form * Adds base error to Pack Form * Adds errors to confirm invite form * Adds clearErrors action * clear errors when confirm invite page unmounts * Handle errors in the App Setting page * Handle server errors in the User Settings Page * Handle server errors in the User Management Page
35 lines
750 B
JavaScript
35 lines
750 B
JavaScript
import { get, join, pickBy } from 'lodash';
|
|
|
|
export const entitiesExceptID = (entities, id) => {
|
|
return pickBy(entities, (entity, key) => {
|
|
return String(key) !== String(id);
|
|
});
|
|
};
|
|
|
|
const formatServerErrors = (errors) => {
|
|
if (!errors || !errors.length) {
|
|
return {};
|
|
}
|
|
|
|
const result = {};
|
|
|
|
errors.forEach((error) => {
|
|
const { name, reason } = error;
|
|
|
|
if (result[name]) {
|
|
result[name] = join([result[name], reason], ', ');
|
|
} else {
|
|
result[name] = reason;
|
|
}
|
|
});
|
|
|
|
return result;
|
|
};
|
|
|
|
export const formatErrorResponse = (errorResponse) => {
|
|
const errors = get(errorResponse, 'message.errors') || [];
|
|
|
|
return formatServerErrors(errors);
|
|
};
|
|
|
|
export default { entitiesExceptID, formatErrorResponse };
|