Skip to content

Commit 0ce324d

Browse files
committed
edit
1 parent 41b39fe commit 0ce324d

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

custom-redirect.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@ let errorGif = "";
1010
const REDIRECT = {
1111
/**
1212
* Generates HTML content with appropriate Canva URL
13+
* @param {boolean} enableReportError - Whether to include the report button
1314
* @returns {string} The HTML with injected URL
1415
*/
15-
generateErrorPage: () => {
16-
return errorTemplate
17-
.replace('ERROR_CODE', errorCode)
18-
.replace('ERROR_TYPE', errorType)
19-
.replace('ERROR_MESSAGE', errorMessage)
20-
.replace('ERROR_GIF', errorGif);
16+
generateErrorPage: (enableReportError = false) => {
17+
let page = errorTemplate
18+
.replace('ERROR_CODE', errorCode)
19+
.replace('ERROR_TYPE', errorType)
20+
.replace('ERROR_MESSAGE', errorMessage)
21+
.replace('ERROR_GIF', errorGif);
22+
23+
if (!enableReportError) {
24+
page = page.replace(
25+
/<!-- BEGIN_REPORT_BUTTON -->.*?<!-- END_REPORT_BUTTON -->/s,
26+
''
27+
);
28+
}
29+
30+
return page;
2131
}
2232
};
2333

html/error-template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
<div id="error-message" class="error-message">ERROR_MESSAGE</div>
2323
<img class="gif" src="ERROR_GIF" alt="Error illustration">
2424
<!-- Conditionally render the report button -->
25-
<!-- If ENABLE_REPORT_ERROR is true, render the button -->
26-
<!-- Placeholder for server-side rendering -->
2725
<!-- BEGIN_REPORT_BUTTON -->
28-
<button id="open-report-modal" class="report-btn" data-link="" data-site="">Signaler cette erreur</button>
26+
<!-- The button will only be rendered if ENABLE_REPORT_ERROR is true -->
27+
<!-- This placeholder will be dynamically replaced server-side -->
2928
<!-- END_REPORT_BUTTON -->
3029
</div>
3130
<!-- Embedded front-end script for modal and reporting -->
@@ -194,3 +193,4 @@
194193
</script>
195194
</body>
196195
</html>
196+
</html>

worker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ export default {
158158

159159
// Custom error page
160160
const redirectResponse = await c_redirect(request, response, null, isMaintenance, env);
161-
if (redirectResponse) return redirectResponse;
161+
if (redirectResponse) {
162+
const enableReportError = env.ENABLE_REPORT_ERROR === true;
163+
return new Response(REDIRECT.generateErrorPage(enableReportError), {
164+
status: response?.status || 500,
165+
headers: { 'Content-Type': 'text/html' }
166+
});
167+
}
162168

163169
// Banner injection - check for 4G mode or regular banner
164170
let showBanner = false;

0 commit comments

Comments
 (0)