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/app/core | |
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/app/core')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 3 | ||||
-rw-r--r-- | client/src/app/core/rest/rest-extractor.service.ts | 9 |
2 files changed, 7 insertions, 5 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index fd6062d3f..cdf13186b 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -11,6 +11,7 @@ import { environment } from '../../../environments/environment' | |||
11 | import { RestExtractor } from '../rest/rest-extractor.service' | 11 | import { RestExtractor } from '../rest/rest-extractor.service' |
12 | import { AuthStatus } from './auth-status.model' | 12 | import { AuthStatus } from './auth-status.model' |
13 | import { AuthUser } from './auth-user.model' | 13 | import { AuthUser } from './auth-user.model' |
14 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
14 | 15 | ||
15 | interface UserLoginWithUsername extends UserLogin { | 16 | interface UserLoginWithUsername extends UserLogin { |
16 | access_token: string | 17 | access_token: string |
@@ -94,7 +95,7 @@ export class AuthService { | |||
94 | error => { | 95 | error => { |
95 | let errorMessage = error.message | 96 | let errorMessage = error.message |
96 | 97 | ||
97 | if (error.status === 403) { | 98 | if (error.status === HttpStatusCode.FORBIDDEN_403) { |
98 | errorMessage = $localize`Cannot retrieve OAuth Client credentials: ${error.text}. | 99 | errorMessage = $localize`Cannot retrieve OAuth Client credentials: ${error.text}. |
99 | Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.` | 100 | Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.` |
100 | } | 101 | } |
diff --git a/client/src/app/core/rest/rest-extractor.service.ts b/client/src/app/core/rest/rest-extractor.service.ts index 4b8c1e155..84d9ed074 100644 --- a/client/src/app/core/rest/rest-extractor.service.ts +++ b/client/src/app/core/rest/rest-extractor.service.ts | |||
@@ -3,6 +3,7 @@ import { Injectable } from '@angular/core' | |||
3 | import { Router } from '@angular/router' | 3 | import { Router } from '@angular/router' |
4 | import { dateToHuman } from '@app/helpers' | 4 | import { dateToHuman } from '@app/helpers' |
5 | import { ResultList } from '@shared/models' | 5 | import { ResultList } from '@shared/models' |
6 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
6 | 7 | ||
7 | @Injectable() | 8 | @Injectable() |
8 | export class RestExtractor { | 9 | export class RestExtractor { |
@@ -57,9 +58,9 @@ export class RestExtractor { | |||
57 | errorMessage = errorsArray.join('. ') | 58 | errorMessage = errorsArray.join('. ') |
58 | } else if (err.error && err.error.error) { | 59 | } else if (err.error && err.error.error) { |
59 | errorMessage = err.error.error | 60 | errorMessage = err.error.error |
60 | } else if (err.status === 413) { | 61 | } else if (err.status === HttpStatusCode.PAYLOAD_TOO_LARGE_413) { |
61 | errorMessage = $localize`Media is too large for the server. Please contact you administrator if you want to increase the limit size.` | 62 | errorMessage = $localize`Media is too large for the server. Please contact you administrator if you want to increase the limit size.` |
62 | } else if (err.status === 429) { | 63 | } else if (err.status === HttpStatusCode.TOO_MANY_REQUESTS_429) { |
63 | const secondsLeft = err.headers.get('retry-after') | 64 | const secondsLeft = err.headers.get('retry-after') |
64 | if (secondsLeft) { | 65 | if (secondsLeft) { |
65 | const minutesLeft = Math.floor(parseInt(secondsLeft, 10) / 60) | 66 | const minutesLeft = Math.floor(parseInt(secondsLeft, 10) / 60) |
@@ -67,7 +68,7 @@ export class RestExtractor { | |||
67 | } else { | 68 | } else { |
68 | errorMessage = $localize`Too many attempts, please try again later.` | 69 | errorMessage = $localize`Too many attempts, please try again later.` |
69 | } | 70 | } |
70 | } else if (err.status === 500) { | 71 | } else if (err.status === HttpStatusCode.INTERNAL_SERVER_ERROR_500) { |
71 | errorMessage = $localize`Server error. Please retry later.` | 72 | errorMessage = $localize`Server error. Please retry later.` |
72 | } | 73 | } |
73 | 74 | ||
@@ -92,7 +93,7 @@ export class RestExtractor { | |||
92 | return observableThrowError(errorObj) | 93 | return observableThrowError(errorObj) |
93 | } | 94 | } |
94 | 95 | ||
95 | redirectTo404IfNotFound (obj: { status: number }, status = [ 404 ]) { | 96 | redirectTo404IfNotFound (obj: { status: number }, status = [ HttpStatusCode.NOT_FOUND_404 ]) { |
96 | if (obj && obj.status && status.indexOf(obj.status) !== -1) { | 97 | if (obj && obj.status && status.indexOf(obj.status) !== -1) { |
97 | // Do not use redirectService to avoid circular dependencies | 98 | // Do not use redirectService to avoid circular dependencies |
98 | this.router.navigate([ '/404' ], { skipLocationChange: true }) | 99 | this.router.navigate([ '/404' ], { skipLocationChange: true }) |