Download next.js/turbopack/crates/turbopack-node/src/render/error_page.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-node/src/render/error_page.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-node/src/render/error_page.rs
-
curl -L -o error_page.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-node/src/render/error_page.rs
1.34 kB
| use anyhow::{Context, Result}; | |
| use turbo_rcstr::RcStr; | |
| use turbo_tasks::Vc; | |
| use turbo_tasks_fs::embed_file; | |
| pub(super) async fn error_html( | |
| status_code: u16, | |
| title: RcStr, | |
| details: RcStr, | |
| ) -> Result<Vc<RcStr>> { | |
| let html = create_html(status_code, title, details).await?; | |
| Ok(Vc::cell(html.into())) | |
| } | |
| pub(super) async fn error_html_body( | |
| status_code: u16, | |
| title: RcStr, | |
| details: RcStr, | |
| ) -> Result<Vc<RcStr>> { | |
| let html = create_html(status_code, title, details).await?; | |
| let (_, body) = html.split_once("<body>").context("no body in html")?; | |
| let (body, _) = body.split_once("</body>").context("no body in html")?; | |
| Ok(Vc::cell(body.into())) | |
| } | |
| async fn create_html(status_code: u16, title: RcStr, details: RcStr) -> Result<String> { | |
| let file_content = embed_file!("src/render/error.html").await?; | |
| let file = file_content | |
| .as_content() | |
| .context("embedded file not found (this should not happen)")?; | |
| let html = file | |
| .content() | |
| .to_str() | |
| .context("couldn't convert embedded html to string")?; | |
| let html = html.replace("${TITLE}", &title); | |
| let html = html.replace("${STATUS_CODE}", &status_code.to_string()); | |
| let html = html.replace("${DETAILS}", &details); | |
| Ok(html) | |
| } | |