aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-02 18:15:41 +0200
committerChocobozzz <me@florianbigard.com>2021-06-02 18:15:41 +0200
commite030bfb59dd5ee65f20a64686ec9b22ca39f70ae (patch)
treec9a439159ef540291e3c030bcaf958b953442147 /client/src/app
parent463206948d6a9d46e7e68d55c7b763e601ecc870 (diff)
downloadPeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.tar.gz
PeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.tar.zst
PeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.zip
Refactor server errors handler
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts8
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts6
-rw-r--r--client/src/app/+videos/+video-watch/video-watch.component.ts8
-rw-r--r--client/src/app/shared/shared-main/auth/auth-interceptor.service.ts5
4 files changed, 18 insertions, 9 deletions
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
index 727bbc32f..15178a267 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
@@ -8,7 +8,7 @@ import { FormValidatorService } from '@app/shared/shared-forms'
8import { VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' 8import { VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
9import { LiveVideoService } from '@app/shared/shared-video-live' 9import { LiveVideoService } from '@app/shared/shared-video-live'
10import { LoadingBarService } from '@ngx-loading-bar/core' 10import { LoadingBarService } from '@ngx-loading-bar/core'
11import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, ServerErrorCode, VideoPrivacy } from '@shared/models' 11import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, PeerTubeProblemDocument, ServerErrorCode, VideoPrivacy } from '@shared/models'
12import { VideoSend } from './video-send' 12import { VideoSend } from './video-send'
13 13
14@Component({ 14@Component({
@@ -92,9 +92,11 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, AfterView
92 92
93 let message = err.message 93 let message = err.message
94 94
95 if (err.body?.code === ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED) { 95 const error = err.body as PeerTubeProblemDocument
96
97 if (error?.code === ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED) {
96 message = $localize`Cannot create live because this instance have too many created lives` 98 message = $localize`Cannot create live because this instance have too many created lives`
97 } else if (err.body?.code) { 99 } else if (error?.code === ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED) {
98 message = $localize`Cannot create live because you created too many lives` 100 message = $localize`Cannot create live because you created too many lives`
99 } 101 }
100 102
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
index 23bd5ef76..2837b30c1 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
@@ -5,7 +5,7 @@ import { scrollToTop } from '@app/helpers'
5import { FormValidatorService } from '@app/shared/shared-forms' 5import { FormValidatorService } from '@app/shared/shared-forms'
6import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main' 6import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
7import { LoadingBarService } from '@ngx-loading-bar/core' 7import { LoadingBarService } from '@ngx-loading-bar/core'
8import { ServerErrorCode, VideoPrivacy, VideoUpdate } from '@shared/models' 8import { PeerTubeProblemDocument, ServerErrorCode, VideoPrivacy, VideoUpdate } from '@shared/models'
9import { hydrateFormFromVideo } from '../shared/video-edit-utils' 9import { hydrateFormFromVideo } from '../shared/video-edit-utils'
10import { VideoSend } from './video-send' 10import { VideoSend } from './video-send'
11 11
@@ -115,7 +115,9 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af
115 this.firstStepError.emit() 115 this.firstStepError.emit()
116 116
117 let message = err.message 117 let message = err.message
118 if (err.body?.code === ServerErrorCode.INCORRECT_FILES_IN_TORRENT) { 118
119 const error = err.body as PeerTubeProblemDocument
120 if (error?.code === ServerErrorCode.INCORRECT_FILES_IN_TORRENT) {
119 message = $localize`Torrents with only 1 file are supported.` 121 message = $localize`Torrents with only 1 file are supported.`
120 } 122 }
121 123
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 8034ccebf..540b568ed 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -28,7 +28,7 @@ import { VideoActionsDisplayType, VideoDownloadComponent } from '@app/shared/sha
28import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' 28import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
29import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' 29import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
30import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 30import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
31import { ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' 31import { PeerTubeProblemDocument, ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models'
32import { 32import {
33 cleanupVideoWatch, 33 cleanupVideoWatch,
34 getStoredP2PEnabled, 34 getStoredP2PEnabled,
@@ -431,9 +431,11 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
431 .pipe( 431 .pipe(
432 // If 400, 403 or 404, the video is private or blocked so redirect to 404 432 // If 400, 403 or 404, the video is private or blocked so redirect to 404
433 catchError(err => { 433 catchError(err => {
434 if (err.body.type === ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS && err.body.originUrl) { 434 const errorBody = err.body as PeerTubeProblemDocument
435
436 if (errorBody.code === ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS && errorBody.originUrl) {
435 const search = window.location.search 437 const search = window.location.search
436 let originUrl = err.body.originUrl 438 let originUrl = errorBody.originUrl
437 if (search) originUrl += search 439 if (search) originUrl += search
438 440
439 this.confirmService.confirm( 441 this.confirmService.confirm(
diff --git a/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts b/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts
index 4fe3b964d..5bcad36d0 100644
--- a/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts
+++ b/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts
@@ -5,6 +5,7 @@ import { Injectable, Injector } from '@angular/core'
5import { AuthService } from '@app/core/auth/auth.service' 5import { AuthService } from '@app/core/auth/auth.service'
6import { Router } from '@angular/router' 6import { Router } from '@angular/router'
7import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 7import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
8import { OAuth2ErrorCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models/server'
8 9
9@Injectable() 10@Injectable()
10export class AuthInterceptor implements HttpInterceptor { 11export class AuthInterceptor implements HttpInterceptor {
@@ -25,7 +26,9 @@ export class AuthInterceptor implements HttpInterceptor {
25 return next.handle(authReq) 26 return next.handle(authReq)
26 .pipe( 27 .pipe(
27 catchError((err: HttpErrorResponse) => { 28 catchError((err: HttpErrorResponse) => {
28 if (err.status === HttpStatusCode.UNAUTHORIZED_401 && err.error && err.error.code === 'invalid_token') { 29 const error = err.error as PeerTubeProblemDocument
30
31 if (err.status === HttpStatusCode.UNAUTHORIZED_401 && error && error.code === OAuth2ErrorCode.INVALID_TOKEN) {
29 return this.handleTokenExpired(req, next) 32 return this.handleTokenExpired(req, next)
30 } 33 }
31 34