diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-08 21:16:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 21:16:10 +0100 |
commit | f2eb23cd87cf32b8fe545178143b5f49e06a58da (patch) | |
tree | af7d59945af70e28fd85047e2c688c59a908f548 /client/src/standalone/videos/embed.ts | |
parent | c977fd3ec931c059111ddb2b8d6ddbb20b6b99a1 (diff) | |
download | PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.tar.gz PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.tar.zst PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.zip |
emit more specific status codes on video upload (#3423)
- reduce http status codes list to potentially useful codes
- convert more codes to typed ones
- factorize html generator for error responses
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r-- | client/src/standalone/videos/embed.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 48f7e7749..1709d44e7 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -13,6 +13,7 @@ import { | |||
13 | PluginType, | 13 | PluginType, |
14 | ClientHookName | 14 | ClientHookName |
15 | } from '../../../../shared/models' | 15 | } from '../../../../shared/models' |
16 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
16 | import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager' | 17 | import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager' |
17 | import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' | 18 | import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' |
18 | import { TranslationsManager } from '../../assets/player/translations-manager' | 19 | import { TranslationsManager } from '../../assets/player/translations-manager' |
@@ -85,7 +86,7 @@ export class PeerTubeEmbed { | |||
85 | refreshFetch (url: string, options?: RequestInit) { | 86 | refreshFetch (url: string, options?: RequestInit) { |
86 | return fetch(url, options) | 87 | return fetch(url, options) |
87 | .then((res: Response) => { | 88 | .then((res: Response) => { |
88 | if (res.status !== 401) return res | 89 | if (res.status !== HttpStatusCode.UNAUTHORIZED_401) return res |
89 | 90 | ||
90 | const refreshingTokenPromise = new Promise((resolve, reject) => { | 91 | const refreshingTokenPromise = new Promise((resolve, reject) => { |
91 | const clientId: string = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID) | 92 | const clientId: string = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID) |
@@ -107,7 +108,7 @@ export class PeerTubeEmbed { | |||
107 | method: 'POST', | 108 | method: 'POST', |
108 | body: objectToUrlEncoded(data) | 109 | body: objectToUrlEncoded(data) |
109 | }).then(res => { | 110 | }).then(res => { |
110 | if (res.status === 401) return undefined | 111 | if (res.status === HttpStatusCode.UNAUTHORIZED_401) return undefined |
111 | 112 | ||
112 | return res.json() | 113 | return res.json() |
113 | }).then((obj: UserRefreshToken & { code: 'invalid_grant'}) => { | 114 | }).then((obj: UserRefreshToken & { code: 'invalid_grant'}) => { |
@@ -338,7 +339,7 @@ export class PeerTubeEmbed { | |||
338 | 339 | ||
339 | try { | 340 | try { |
340 | playlistResponse = await playlistPromise | 341 | playlistResponse = await playlistPromise |
341 | isResponseOk = playlistResponse.status === 200 | 342 | isResponseOk = playlistResponse.status === HttpStatusCode.OK_200 |
342 | } catch (err) { | 343 | } catch (err) { |
343 | console.error(err) | 344 | console.error(err) |
344 | isResponseOk = false | 345 | isResponseOk = false |
@@ -347,7 +348,7 @@ export class PeerTubeEmbed { | |||
347 | if (!isResponseOk) { | 348 | if (!isResponseOk) { |
348 | const serverTranslations = await this.translationsPromise | 349 | const serverTranslations = await this.translationsPromise |
349 | 350 | ||
350 | if (playlistResponse?.status === 404) { | 351 | if (playlistResponse?.status === HttpStatusCode.NOT_FOUND_404) { |
351 | this.playlistNotFound(serverTranslations) | 352 | this.playlistNotFound(serverTranslations) |
352 | return undefined | 353 | return undefined |
353 | } | 354 | } |
@@ -367,7 +368,7 @@ export class PeerTubeEmbed { | |||
367 | 368 | ||
368 | try { | 369 | try { |
369 | videoResponse = await videoPromise | 370 | videoResponse = await videoPromise |
370 | isResponseOk = videoResponse.status === 200 | 371 | isResponseOk = videoResponse.status === HttpStatusCode.OK_200 |
371 | } catch (err) { | 372 | } catch (err) { |
372 | console.error(err) | 373 | console.error(err) |
373 | 374 | ||
@@ -377,7 +378,7 @@ export class PeerTubeEmbed { | |||
377 | if (!isResponseOk) { | 378 | if (!isResponseOk) { |
378 | const serverTranslations = await this.translationsPromise | 379 | const serverTranslations = await this.translationsPromise |
379 | 380 | ||
380 | if (videoResponse?.status === 404) { | 381 | if (videoResponse?.status === HttpStatusCode.NOT_FOUND_404) { |
381 | this.videoNotFound(serverTranslations) | 382 | this.videoNotFound(serverTranslations) |
382 | return undefined | 383 | return undefined |
383 | } | 384 | } |