{"record":{"id":"242479ab1180bfb2","repo":"jaredpalmer/formik","slug":"warning-an-unhandled-error-was-caught-from-submit","errorCode":null,"errorMessage":"Warning: An unhandled error was caught from submitForm()","messagePattern":"Warning: An unhandled error was caught from submitForm\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/formik/src/Formik.tsx","lineNumber":837,"sourceCode":"      // a common gotcha in forms with both reset and submit buttons,\n      // where the dev forgets to add type=\"button\" to the reset button.\n      if (__DEV__ && typeof document !== 'undefined') {\n        // Safely get the active element (works with IE)\n        const activeElement = getActiveElement();\n        if (\n          activeElement !== null &&\n          activeElement instanceof HTMLButtonElement\n        ) {\n          invariant(\n            activeElement.attributes &&\n              activeElement.attributes.getNamedItem('type'),\n            'You submitted a Formik form using a button with an unspecified `type` attribute.  Most browsers default button elements to `type=\"submit\"`. If this is not a submit button, please add `type=\"button\"`.'\n          );\n        }\n      }\n\n      submitForm().catch(reason => {\n        console.warn(\n          `Warning: An unhandled error was caught from submitForm()`,\n          reason\n        );\n      });\n    }\n  );\n\n  const imperativeMethods: FormikHelpers<Values> = {\n    resetForm,\n    validateForm: validateFormWithHighPriority,\n    validateField,\n    setErrors,\n    setFieldError,\n    setFieldTouched,\n    setFieldValue,\n    setStatus,\n    setSubmitting,\n    setTouched,","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/jaredpalmer/formik/blob/91475adbf33579561e580eceea0c031f4ec2e992/packages/formik/src/Formik.tsx#L819-L855","documentation":"Your `onSubmit` (or the submission pipeline) returned/returned a Promise that rejected, and nothing handled it — Formik's internal `handleSubmit` attaches a `.catch` that only logs. This almost always means `onSubmit` threw unexpectedly (not a normal validation flow), or you use `setSubmitting(false)` incorrectly after an awaited failure.","triggerScenarios":"`onSubmit` throws synchronously or its async function rejects (network error, undefined access) without an internal try/catch; or code calls `formikProps.submitForm()` without `.catch`. In this specific source, the Formik-rendered submit handler fires `submitForm()` and any rejection lands in this catch.","commonSituations":"API call inside onSubmit fails (4xx/5xx/network) and is not caught; forgetting try/finally around async submit so setSubmitting(false) never runs; mutation on a response like `res.data.foo` when the request errored.","solutions":["Add try/catch inside onSubmit; on failure call setErrors or setFieldError instead of letting it reject.","Always use `finally { setSubmitting(false) }` so submit state resets even on failure.","If you call submitForm() yourself, attach `.catch(errors => ...)` to handle submission errors explicitly."],"exampleFix":"// before\nonSubmit: async values => {\n  await api.save(values); // rejection => unhandled\n  setSubmitting(false);\n}\n// after\nonSubmit: async (values, { setErrors, setSubmitting }) => {\n  try {\n    await api.save(values);\n  } catch (e) {\n    setErrors({ submit: 'Save failed' });\n  } finally {\n    setSubmitting(false);\n  }\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"onSubmit: async (values, { setErrors, setSubmitting }) => {\n  try {\n    await api.save(values);\n  } catch (e: any) {\n    setErrors({ submit: e?.message ?? 'Submission failed' });\n  } finally {\n    setSubmitting(false);\n  }\n}\n// and if calling manually:\nformik.submitForm().catch(err => setSubmitError(err));","preventionTips":["Never let onSubmit reject; catch and map to setErrors/setFieldError","Use finally to reset isSubmitting","Add a global ErrorBoundary for render-time fallout from bad submit state"],"tags":["formik","submit","onsubmit","unhandled-rejection","async"],"backgroundTag":"form-submit-handler-error","analyzedSha":"91475adbf33579561e580eceea0c031f4ec2e992","analyzedAt":"2026-08-27T12:26:57.937Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}