diff --git a/src/helpers/formik.ts b/src/helpers/formik.ts new file mode 100644 index 00000000..4dbbb79c --- /dev/null +++ b/src/helpers/formik.ts @@ -0,0 +1,16 @@ +export function setFormErrors( + error: unknown, + setErrors: (errors: object) => void +): void { + if (typeof error !== 'object' || + error === null || + !('status' in error) || + typeof error.status !== 'number' || + error.status !== 400 || + !('data' in error) || + typeof error.data !== 'object' || + error.data === null + ) { throw error; } + + setErrors(error.data); +}