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)
)
)
}