Fixed handling of 4xx status codes when using instant loading

This commit is contained in:
squidfunk
2022-05-07 09:22:05 +02:00
parent 684acdcc78
commit 8beda2bfe1
14 changed files with 81 additions and 63 deletions

View File

@@ -24,11 +24,12 @@ import {
EMPTY,
Observable,
catchError,
filter,
from,
map,
of,
shareReplay,
switchMap
switchMap,
throwError
} from "rxjs"
/* ----------------------------------------------------------------------------
@@ -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)
)
)
}

View File

@@ -22,7 +22,9 @@
import { Repo, User } from "github-types"
import {
EMPTY,
Observable,
catchError,
defaultIfEmpty,
map,
zip
@@ -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
})),
@@ -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

View File

@@ -22,7 +22,9 @@
import { ProjectSchema } from "gitlab"
import {
EMPTY,
Observable,
catchError,
defaultIfEmpty,
map
} from "rxjs"
@@ -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

View File

@@ -21,7 +21,9 @@
*/
import {
EMPTY,
Observable,
catchError,
defaultIfEmpty,
map,
of,
@@ -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))
)

View File

@@ -23,6 +23,7 @@
import {
EMPTY,
Subject,
catchError,
combineLatest,
filter,
fromEvent,
@@ -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$