From 4d3ea87486e095aa7934888b66443cfce6804894 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 21 Aug 2023 15:32:33 +0200 Subject: More robust about page Don't throw if we can't find a category or a language Can happen if the instance configuration contains a category/language that has been deleted by a plugin for example --- .../app/shared/shared-instance/instance.service.ts | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'client') diff --git a/client/src/app/shared/shared-instance/instance.service.ts b/client/src/app/shared/shared-instance/instance.service.ts index 9a55cf972..58bf8ee54 100644 --- a/client/src/app/shared/shared-instance/instance.service.ts +++ b/client/src/app/shared/shared-instance/instance.service.ts @@ -6,6 +6,7 @@ import { MarkdownService, RestExtractor, ServerService } from '@app/core' import { objectKeysTyped, peertubeTranslate } from '@peertube/peertube-core-utils' import { About } from '@peertube/peertube-models' import { environment } from '../../../environments/environment' +import { logger } from '@root-helpers/logger' export type AboutHTML = Pick { return about.instance.languages - .map(l => { - const languageObj = languagesArray.find(la => la.id === l) + .map(l => { + const languageObj = languagesArray.find(la => la.id === l) + if (!languageObj) { + logger.error(`Cannot find language ${l} in available languages`) + return '' + } - return peertubeTranslate(languageObj.label, translations) - }) + return peertubeTranslate(languageObj.label, translations) + }) }) ) } @@ -85,11 +90,15 @@ export class InstanceService { ]).pipe( map(([ categoriesArray, translations ]) => { return about.instance.categories - .map(c => { - const categoryObj = categoriesArray.find(ca => ca.id === c) + .map(c => { + const categoryObj = categoriesArray.find(ca => ca.id === c) + if (!categoryObj) { + logger.error(`Cannot find instance category ${c} in available categories`) + return '' + } - return peertubeTranslate(categoryObj.label, translations) - }) + return peertubeTranslate(categoryObj.label, translations) + }) }) ) } -- cgit v1.2.3