Skip to content

Commit

Permalink
Fixed handling of 4xx status codes when using instant loading
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed May 7, 2022
1 parent 684acdc commit 8beda2b
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 63 deletions.
29 changes: 29 additions & 0 deletions material/assets/javascripts/bundle.c2e1ee47.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions material/assets/javascripts/bundle.ed9748b7.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion material/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.ed9748b7.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.c2e1ee47.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}
Expand Down
18 changes: 18 additions & 0 deletions material/overrides/assets/javascripts/bundle.2bc01bfd.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions material/overrides/assets/javascripts/bundle.641d98f2.min.js

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion material/overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
{% endblock %}
{% block scripts %}
{{ super() }}
<script src="{{ 'overrides/assets/javascripts/bundle.641d98f2.min.js' | url }}"></script>
<script src="{{ 'overrides/assets/javascripts/bundle.2bc01bfd.min.js' | url }}"></script>
{% endblock %}
12 changes: 8 additions & 4 deletions src/assets/javascripts/browser/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import {
EMPTY,
Observable,
catchError,
filter,
from,
map,
of,
shareReplay,
switchMap
switchMap,
throwError
} from "rxjs"

/* ----------------------------------------------------------------------------
Expand All @@ -51,8 +52,11 @@ export function request(
): Observable<Response> {
return from(fetch(`${url}`, options))
.pipe(
filter(res => res.status === 200),
catchError(() => EMPTY)
catchError(() => EMPTY),
switchMap(res => res.status !== 200
? throwError(() => new Error(res.statusText))
: of(res)
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

import { Repo, User } from "github-types"
import {
EMPTY,
Observable,
catchError,
defaultIfEmpty,
map,
zip
Expand Down Expand Up @@ -65,6 +67,7 @@ export function fetchSourceFactsFromGitHub(
/* Fetch version */
requestJSON<Release>(`${url}/releases/latest`)
.pipe(
catchError(() => EMPTY), // @todo refactor instant loading
map(release => ({
version: release.tag_name
})),
Expand All @@ -74,6 +77,7 @@ export function fetchSourceFactsFromGitHub(
/* Fetch stars and forks */
requestJSON<Repo>(url)
.pipe(
catchError(() => EMPTY), // @todo refactor instant loading
map(info => ({
stars: info.stargazers_count,
forks: info.forks_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

import { ProjectSchema } from "gitlab"
import {
EMPTY,
Observable,
catchError,
defaultIfEmpty,
map
} from "rxjs"
Expand All @@ -49,6 +51,7 @@ export function fetchSourceFactsFromGitLab(
const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}`
return requestJSON<ProjectSchema>(url)
.pipe(
catchError(() => EMPTY), // @todo refactor instant loading
map(({ star_count, forks_count }) => ({
stars: star_count,
forks: forks_count
Expand Down
3 changes: 3 additions & 0 deletions src/assets/javascripts/integrations/sitemap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/

import {
EMPTY,
Observable,
catchError,
defaultIfEmpty,
map,
of,
Expand Down Expand Up @@ -97,6 +99,7 @@ export function fetchSitemap(base?: URL): Observable<Sitemap> {
map(sitemap => preprocess(getElements("loc", sitemap)
.map(node => node.textContent!)
)),
catchError(() => EMPTY), // @todo refactor instant loading
defaultIfEmpty([]),
tap(sitemap => __md_set("__sitemap", sitemap, sessionStorage, base))
)
Expand Down
4 changes: 4 additions & 0 deletions src/assets/javascripts/integrations/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import {
EMPTY,
Subject,
catchError,
combineLatest,
filter,
fromEvent,
Expand Down Expand Up @@ -73,6 +74,9 @@ export function setupVersionSelector(
const versions$ = requestJSON<Version[]>(
new URL("../versions.json", config.base)
)
.pipe(
catchError(() => EMPTY) // @todo refactor instant loading
)

/* Determine current version */
const current$ = versions$
Expand Down

0 comments on commit 8beda2b

Please sign in to comment.