aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-07 09:13:32 +0200
committerChocobozzz <me@florianbigard.com>2020-08-07 09:13:32 +0200
commitbe59656c82d641118cd6d468cd11be1e057428d1 (patch)
tree40b86d2991f1941a07d9e83eeab667a5dd20c526 /client/src
parent92d54714b91a8e1619d49efac26ea0977a27f532 (diff)
downloadPeerTube-be59656c82d641118cd6d468cd11be1e057428d1.tar.gz
PeerTube-be59656c82d641118cd6d468cd11be1e057428d1.tar.zst
PeerTube-be59656c82d641118cd6d468cd11be1e057428d1.zip
Correctly error network errors in embed
Diffstat (limited to 'client/src')
-rw-r--r--client/src/standalone/videos/embed.ts39
1 files changed, 29 insertions, 10 deletions
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 {
136 } 136 }
137 137
138 loadVideoCaptions (videoId: string): Promise<Response> { 138 loadVideoCaptions (videoId: string): Promise<Response> {
139 return fetch(this.getVideoUrl(videoId) + '/captions') 139 return this.refreshFetch(this.getVideoUrl(videoId) + '/captions', { headers: this.headers })
140 } 140 }
141 141
142 loadPlaylistInfo (playlistId: string): Promise<Response> { 142 loadPlaylistInfo (playlistId: string): Promise<Response> {
143 return fetch(this.getPlaylistUrl(playlistId)) 143 return this.refreshFetch(this.getPlaylistUrl(playlistId), { headers: this.headers })
144 } 144 }
145 145
146 loadPlaylistElements (playlistId: string, start = 0): Promise<Response> { 146 loadPlaylistElements (playlistId: string, start = 0): Promise<Response> {
147 const url = new URL(this.getPlaylistUrl(playlistId) + '/videos') 147 const url = new URL(this.getPlaylistUrl(playlistId) + '/videos')
148 url.search = new URLSearchParams({ start: '' + start, count: '100' }).toString() 148 url.search = new URLSearchParams({ start: '' + start, count: '100' }).toString()
149 149
150 return fetch(url.toString()) 150 return this.refreshFetch(url.toString(), { headers: this.headers })
151 } 151 }
152 152
153 loadConfig (): Promise<ServerConfig> { 153 loadConfig (): Promise<ServerConfig> {
154 return fetch('/api/v1/config') 154 return this.refreshFetch('/api/v1/config')
155 .then(res => res.json()) 155 .then(res => res.json())
156 } 156 }
157 157
@@ -318,12 +318,21 @@ export class PeerTubeEmbed {
318 const playlistPromise = this.loadPlaylistInfo(playlistId) 318 const playlistPromise = this.loadPlaylistInfo(playlistId)
319 const playlistElementsPromise = this.loadPlaylistElements(playlistId) 319 const playlistElementsPromise = this.loadPlaylistElements(playlistId)
320 320
321 const playlistResponse = await playlistPromise 321 let playlistResponse: Response
322 let isResponseOk: boolean
322 323
323 if (!playlistResponse.ok) { 324 try {
325 playlistResponse = await playlistPromise
326 isResponseOk = true
327 } catch (err) {
328 console.error(err)
329 isResponseOk = false
330 }
331
332 if (!isResponseOk) {
324 const serverTranslations = await this.translationsPromise 333 const serverTranslations = await this.translationsPromise
325 334
326 if (playlistResponse.status === 404) { 335 if (playlistResponse?.status === 404) {
327 this.playlistNotFound(serverTranslations) 336 this.playlistNotFound(serverTranslations)
328 return undefined 337 return undefined
329 } 338 }
@@ -338,12 +347,22 @@ export class PeerTubeEmbed {
338 private async loadVideo (videoId: string) { 347 private async loadVideo (videoId: string) {
339 const videoPromise = this.loadVideoInfo(videoId) 348 const videoPromise = this.loadVideoInfo(videoId)
340 349
341 const videoResponse = await videoPromise 350 let videoResponse: Response
351 let isResponseOk: boolean
352
353 try {
354 videoResponse = await videoPromise
355 isResponseOk = true
356 } catch (err) {
357 console.error(err)
358
359 isResponseOk = false
360 }
342 361
343 if (!videoResponse.ok) { 362 if (!isResponseOk) {
344 const serverTranslations = await this.translationsPromise 363 const serverTranslations = await this.translationsPromise
345 364
346 if (videoResponse.status === 404) { 365 if (videoResponse?.status === 404) {
347 this.videoNotFound(serverTranslations) 366 this.videoNotFound(serverTranslations)
348 return undefined 367 return undefined
349 } 368 }