{"record":{"id":"6750436c45909e13","repo":"halo-dev/halo","slug":"i18nresources-sendverificationcodefailed","errorCode":null,"errorMessage":"i18nResources.sendVerificationCodeFailed","messagePattern":"i18nResources\\.sendVerificationCodeFailed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"application/src/main/resources/templates/gateway_fragments/complete_profile.html","lineNumber":92,"sourceCode":"        const email = document.getElementById(\"email\").value;\n        const response = await fetch(\"/complete-profile/send-email-code\", {\n          method: \"POST\",\n          body: JSON.stringify({ email: email }),\n          headers: {\n            \"Content-Type\": \"application/json\",\n            [headerName]: token,\n          },\n        });\n\n        if (!response.ok) {\n          const json = await response.json();\n          if (json.errors && json.errors.length) {\n            throw new Error(json.errors[0]);\n          }\n          if (json.detail) {\n            throw new Error(json.detail);\n          }\n          throw new Error(i18nResources.sendVerificationCodeFailed);\n        }\n\n        return response;\n      }\n\n      const emailCodeSendButton = document.getElementById(\"emailCodeSendButton\");\n      sendVerificationCode(emailCodeSendButton, sendRequest);\n    });\n  </script>\n</form>\n","sourceCodeStart":74,"sourceCodeEnd":103,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/resources/templates/gateway_fragments/complete_profile.html#L74-L103","documentation":"Client-side JS fallback in the complete-profile flow: when /complete-profile/send-email-code returns a non-ok response whose body has neither a usable errors array nor a detail field, sendRequest() throws new Error(i18nResources.sendVerificationCodeFailed) — a generic localized message ('Sending Failed, Please Try Again Later' / '发送失败，请稍后再试'). It is the catch-all branch so the user always sees some message.","triggerScenarios":"The response is not ok but the body shape is unexpected: empty body, non-JSON body, network/proxy error page (HTML), or a JSON object lacking both errors and detail.","commonSituations":"Reverse proxy returning an HTML error page (502/504) with JSON parse yielding an object without errors/detail; response body empty; network glitch; the endpoint changed its error contract.","solutions":["Open DevTools -> Network and inspect the raw response status and body to see why it is not ok and why no errors/detail were found.","Retry the request; transient gateway/network errors usually clear.","Refresh the page to reset CSRF and session state.","If persistent, check that the backend /complete-profile/send-email-code route is up and returning its documented error shape."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Guard against non-JSON / unexpected bodies before throwing:\nlet json;\ntry { json = await response.json(); } catch { json = null; }\nif (json?.errors?.length) throw new Error(json.errors[0]);\nif (json?.detail) throw new Error(json.detail);\n// Provide a richer fallback using response.status:\nthrow new Error(`${i18nResources.sendVerificationCodeFailed} (HTTP ${response.status})`);","typeGuard":"function hasUsableErrorBody(json) {\n  return json != null &&\n    ((Array.isArray(json.errors) && json.errors.length > 0) ||\n     (typeof json.detail === \"string\" && json.detail.length > 0));\n}","tryCatchPattern":"try {\n    await sendRequest();\n} catch (e) {\n    // generic localized failure\n    showToast(i18nResources.sendVerificationCodeFailed);\n    console.error(\"send-email-code failed:\", e);\n}","preventionTips":["Include the HTTP status in the fallback message to aid debugging.","Inspect the raw response in DevTools when this generic message appears.","Keep the backend error contract (errors[] / detail) stable for the frontend.","Retry once for transient gateway/network errors."],"tags":["frontend","javascript","email-verification","complete-profile","fallback"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}