From be59656c82d641118cd6d468cd11be1e057428d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 Aug 2020 09:13:32 +0200 Subject: Correctly error network errors in embed --- client/src/standalone/videos/embed.ts | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'client/src') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 8d1720f75..c927e900e 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -136,22 +136,22 @@ export class PeerTubeEmbed { } loadVideoCaptions (videoId: string): Promise { - return fetch(this.getVideoUrl(videoId) + '/captions') + return this.refreshFetch(this.getVideoUrl(videoId) + '/captions', { headers: this.headers }) } loadPlaylistInfo (playlistId: string): Promise { - return fetch(this.getPlaylistUrl(playlistId)) + return this.refreshFetch(this.getPlaylistUrl(playlistId), { headers: this.headers }) } loadPlaylistElements (playlistId: string, start = 0): Promise { const url = new URL(this.getPlaylistUrl(playlistId) + '/videos') url.search = new URLSearchParams({ start: '' + start, count: '100' }).toString() - return fetch(url.toString()) + return this.refreshFetch(url.toString(), { headers: this.headers }) } loadConfig (): Promise { - return fetch('/api/v1/config') + return this.refreshFetch('/api/v1/config') .then(res => res.json()) } @@ -318,12 +318,21 @@ export class PeerTubeEmbed { const playlistPromise = this.loadPlaylistInfo(playlistId) const playlistElementsPromise = this.loadPlaylistElements(playlistId) - const playlistResponse = await playlistPromise + let playlistResponse: Response + let isResponseOk: boolean - if (!playlistResponse.ok) { + try { + playlistResponse = await playlistPromise + isResponseOk = true + } catch (err) { + console.error(err) + isResponseOk = false + } + + if (!isResponseOk) { const serverTranslations = await this.translationsPromise - if (playlistResponse.status === 404) { + if (playlistResponse?.status === 404) { this.playlistNotFound(serverTranslations) return undefined } @@ -338,12 +347,22 @@ export class PeerTubeEmbed { private async loadVideo (videoId: string) { const videoPromise = this.loadVideoInfo(videoId) - const videoResponse = await videoPromise + let videoResponse: Response + let isResponseOk: boolean + + try { + videoResponse = await videoPromise + isResponseOk = true + } catch (err) { + console.error(err) + + isResponseOk = false + } - if (!videoResponse.ok) { + if (!isResponseOk) { const serverTranslations = await this.translationsPromise - if (videoResponse.status === 404) { + if (videoResponse?.status === 404) { this.videoNotFound(serverTranslations) return undefined } -- cgit v1.2.3