-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support display HTML format in API error responses (#7127)
#### What type of PR is this? /kind feature /area ui /milestone 2.20.x #### What this PR does / why we need it: Add supports for display HTML format in API error responses See #7115 Examples: <img width="917" alt="image" src="https://github.com/user-attachments/assets/1ab4531c-3238-4e7d-ba24-d2425184a757"> <img width="942" alt="image" src="https://github.com/user-attachments/assets/54621b31-0629-4772-95fd-8587a7704ca3"> #### Which issue(s) this PR fixes: Fixes #7115 #### Special notes for your reviewer: Nginx mock example: ```nginx server { listen 80; server_name localhost; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location / { proxy_pass http://localhost:8090; proxy_set_header HOST $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ^~ /apis/content.halo.run/v1alpha1/posts/ { return 403; } } ``` #### Does this PR introduce a user-facing change? ```release-note 支持显示来自反向代理或者 WAF 的请求错误信息 ```
- Loading branch information
Showing
5 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { i18n } from "@/locales"; | ||
import { VButton, VModal } from "@halo-dev/components"; | ||
import { type Component, createApp, h } from "vue"; | ||
|
||
interface ModalOptions { | ||
uniqueId?: string; | ||
title?: string; | ||
width?: number; | ||
height?: string; | ||
centered?: boolean; | ||
content: Component; | ||
} | ||
|
||
export function createHTMLContentModal(options: ModalOptions) { | ||
if (options.uniqueId) { | ||
const existingModal = document.getElementById(`modal-${options.uniqueId}`); | ||
if (existingModal) { | ||
return; | ||
} | ||
} | ||
|
||
const container = document.createElement("div"); | ||
if (options.uniqueId) { | ||
container.id = `modal-${options.uniqueId}`; | ||
} | ||
|
||
document.body.appendChild(container); | ||
|
||
const app = createApp({ | ||
setup() { | ||
const handleClose = () => { | ||
app.unmount(); | ||
container.remove(); | ||
}; | ||
|
||
return () => | ||
h( | ||
VModal, | ||
{ | ||
title: options.title, | ||
width: options.width || 500, | ||
height: options.height, | ||
centered: options.centered ?? true, | ||
onClose: handleClose, | ||
"onUpdate:visible": (value: boolean) => { | ||
if (!value) handleClose(); | ||
}, | ||
}, | ||
{ | ||
default: () => options.content, | ||
footer: () => | ||
h( | ||
VButton, | ||
{ | ||
onClick: handleClose, | ||
}, | ||
{ | ||
default: () => | ||
h("div", i18n.global.t("core.common.buttons.close")), | ||
} | ||
), | ||
} | ||
); | ||
}, | ||
}); | ||
|
||
app.mount(container); | ||
|
||
return { | ||
close: () => { | ||
app.unmount(); | ||
container.remove(); | ||
}, | ||
}; | ||
} |