Skip to content

Commit 4b398c7

Browse files
committed
pat-inject - Better Error Reporting on inject
Change the meta tag name from ``pat-inject-STATUSCODE`` to ``pat-inject-status-STATUSCODE``. pat inject: Allow configurable error pages by defining the error page URLs via meta tags with the name ``pat-inject-status-``. Can be disabled by adding ``pat-inject-errorhandler.off`` to the URL's query string.
1 parent 2ec4837 commit 4b398c7

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
- pat tabs: Refactor based on ``ResizeObserver`` and fix problems calculating the with with transitions.
5555
- pat tabs: When clicking on the ``extra-tabs`` element, toggle between ``open`` and ``closed`` classes to allow opening/closing an extra-tabs menu via CSS.
5656
- pat autofocus: Do not autofocus in iframes. Fixes: #761.
57-
- pat inject: Allow configurable error pages. Can be disabled by adding ``pat-inject-errorhandler.off`` to the URL's query string.
57+
- pat inject: Allow configurable error pages by defining the error page URLs via meta tags with the name ``pat-inject-status-``.
58+
Can be disabled by adding ``pat-inject-errorhandler.off`` to the URL's query string.
5859
- core utils: Add ``jqToNode`` to return a DOM node if a jQuery node was passed.
5960
- pat inject: Rebase URLs in pattern configuration attributes. This avoids URLs in pattern configuration to point to unreachable paths in the context where the result is injected into.
6061

src/pat/inject/documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ After injection was triggered:
328328
In cases of AJAX errors, you can provide custom error pages by providing custom meta tags.
329329
For example, if you add this meta tag to the html ``<head>``:
330330

331-
<meta name="pat-inject-404" content="/test_404.html" />
331+
<meta name="pat-inject-status-404" content="/test_404.html" />
332332

333333
Then, in case of a ``404`` error, it will try to retrieve the error page and replace the document body contents with the body contents of the error page.
334-
The code looks for a meta tag with the name ``pat-inject-`` plus the HTTP status code.
334+
The code looks for a meta tag with the name ``pat-inject-status-`` plus the HTTP status code.
335335

336336
Another example: You can present the user with a login page in case the session has expired (``401`` error).
337337

src/pat/inject/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta name="patterns-push-login" content="guest" />
99
<meta name="patterns-push-password" content="guest" />
1010
<meta name="patterns-push-user-id" content="allan_neece" />
11-
<meta name="pat-inject-404" content="./test_404.html" />
11+
<meta name="pat-inject-status-404" content="./test_404.html" />
1212
<title>Injection pattern</title>
1313
<link rel="stylesheet" href="/style/common.css" type="text/css" />
1414
<script

src/pat/inject/inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ const inject = {
683683
const url_params = new URLSearchParams(window.location.search);
684684

685685
const fallback_url = document
686-
.querySelector(`meta[name=pat-inject-${status}]`)
686+
.querySelector(`meta[name=pat-inject-status-${status}]`)
687687
?.getAttribute("content", false);
688688
if (
689689
fallback_url &&

src/pat/inject/inject.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ describe("pat-inject", function () {
994994

995995
// apparently <head> is empty if we do not set it.
996996
document.head.innerHTML = `
997-
<meta name="pat-inject-404" content="/404.html" />
997+
<meta name="pat-inject-status-404" content="/404.html" />
998998
`;
999999

10001000
pattern.init($a);
@@ -1035,7 +1035,7 @@ describe("pat-inject", function () {
10351035

10361036
// apparently <head> is empty if we do not set it.
10371037
document.head.innerHTML = `
1038-
<meta name="pat-inject-404" content="/404.html" />
1038+
<meta name="pat-inject-status-404" content="/404.html" />
10391039
`;
10401040

10411041
pattern.init($a);

0 commit comments

Comments
 (0)