From f2eb23cd87cf32b8fe545178143b5f49e06a58da Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 8 Dec 2020 21:16:10 +0100 Subject: 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 --- client/src/app/core/auth/auth.service.ts | 3 ++- client/src/app/core/rest/rest-extractor.service.ts | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'client/src/app/core') 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' import { RestExtractor } from '../rest/rest-extractor.service' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' +import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' interface UserLoginWithUsername extends UserLogin { access_token: string @@ -94,7 +95,7 @@ export class AuthService { error => { let errorMessage = error.message - if (error.status === 403) { + if (error.status === HttpStatusCode.FORBIDDEN_403) { errorMessage = $localize`Cannot retrieve OAuth Client credentials: ${error.text}. Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.` } 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' import { Router } from '@angular/router' import { dateToHuman } from '@app/helpers' import { ResultList } from '@shared/models' +import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' @Injectable() export class RestExtractor { @@ -57,9 +58,9 @@ export class RestExtractor { errorMessage = errorsArray.join('. ') } else if (err.error && err.error.error) { errorMessage = err.error.error - } else if (err.status === 413) { + } else if (err.status === HttpStatusCode.PAYLOAD_TOO_LARGE_413) { errorMessage = $localize`Media is too large for the server. Please contact you administrator if you want to increase the limit size.` - } else if (err.status === 429) { + } else if (err.status === HttpStatusCode.TOO_MANY_REQUESTS_429) { const secondsLeft = err.headers.get('retry-after') if (secondsLeft) { const minutesLeft = Math.floor(parseInt(secondsLeft, 10) / 60) @@ -67,7 +68,7 @@ export class RestExtractor { } else { errorMessage = $localize`Too many attempts, please try again later.` } - } else if (err.status === 500) { + } else if (err.status === HttpStatusCode.INTERNAL_SERVER_ERROR_500) { errorMessage = $localize`Server error. Please retry later.` } @@ -92,7 +93,7 @@ export class RestExtractor { return observableThrowError(errorObj) } - redirectTo404IfNotFound (obj: { status: number }, status = [ 404 ]) { + redirectTo404IfNotFound (obj: { status: number }, status = [ HttpStatusCode.NOT_FOUND_404 ]) { if (obj && obj.status && status.indexOf(obj.status) !== -1) { // Do not use redirectService to avoid circular dependencies this.router.navigate([ '/404' ], { skipLocationChange: true }) -- cgit v1.2.3