mirror of
https://github.com/fleetdm/fleet
synced 2026-05-19 23:18:51 +00:00
* all login methods no longer use redux * removed redux from registration * redirect user from registration * removed redux from sso invite * removed redundant component * refactored user settings page * removed redux from logout * cleaned up unused redux calls * lint fixes * removed test * removed old config interface * fixed registration bug * team permission fix * removed remaining redux references from pages - #4436 * better way to set config
36 lines
762 B
TypeScript
36 lines
762 B
TypeScript
import { get, join } from "lodash";
|
|
import { IError } from "interfaces/errors";
|
|
|
|
const formatServerErrors = (errors: IError[]) => {
|
|
if (!errors || !errors.length) {
|
|
return {};
|
|
}
|
|
|
|
const result: { [key: string]: string } = {};
|
|
|
|
errors.forEach((error) => {
|
|
const { name, reason } = error;
|
|
|
|
if (result[name]) {
|
|
result[name] = join([result[name], reason], ", ");
|
|
} else {
|
|
result[name] = reason;
|
|
}
|
|
});
|
|
|
|
return result;
|
|
};
|
|
|
|
const formatErrorResponse = (errorResponse: any) => {
|
|
const errors =
|
|
get(errorResponse, "message.errors") ||
|
|
get(errorResponse, "data.errors") ||
|
|
[];
|
|
|
|
return {
|
|
...formatServerErrors(errors),
|
|
http_status: errorResponse.status,
|
|
} as any;
|
|
};
|
|
|
|
export default formatErrorResponse;
|