Skip to content

Commit

Permalink
feat: support toast a message for backend exceptions when sending ema…
Browse files Browse the repository at this point in the history
…ils (#6856)

#### What type of PR is this?

/area core
/kind improvement
/milestone 2.20.x

#### What this PR does / why we need it:

注册表单发送邮箱验证码时,支持显示来自后端的异常。

<img width="693" alt="image" src="https://github.com/user-attachments/assets/78d1d793-7673-4442-9b0b-1eb7c4d91ebd">


#### Does this PR introduce a user-facing change?

```release-note
None
```
  • Loading branch information
ruibaby authored Oct 13, 2024
1 parent 0d8c4bb commit b0d36b7
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,32 @@

<script th:if="${globalInfo.mustVerifyEmailOnRegistration}" th:inline="javascript">
document.addEventListener("DOMContentLoaded", function () {
function sendRequest() {
return new Promise((resolve, reject) => {
const email = document.getElementById("email").value;
const headerName = /*[[${_csrf.headerName}]]*/ "";
const token = /*[[${_csrf.token}]]*/ "";
async function sendRequest() {
const email = document.getElementById("email").value;
if (!email) {
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/"");
}
if (!email) {
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/ "");
}
fetch("/signup/send-email-code", {
method: "POST",
body: JSON.stringify({ email: email }),
headers: {
"Content-Type": "application/json",
[[${_csrf.headerName}]]: [[${_csrf.token}]],
},
})
.then((response) => {
if (response.ok) {
resolve(response);
}
reject(response);
})
.catch((e) => {
reject(e);
});
const response = await fetch("/signup/send-email-code", {
method: "POST",
body: JSON.stringify({ email: email }),
headers: {
"Content-Type": "application/json",
[headerName]: token,
},
});
if (!response.ok) {
const json = await response.json();
if (json.errors && json.errors.length) {
throw new Error(json.errors[0]);
}
}
return response;
}
const emailCodeSendButton = document.getElementById("emailCodeSendButton");
Expand Down

0 comments on commit b0d36b7

Please sign in to comment.