From d87a43c3a3948f0945969d13532f60462397bd08 Mon Sep 17 00:00:00 2001
From: Marie <marie@kaifa.ch>
Date: Wed, 21 Feb 2024 19:44:12 +0100
Subject: [PATCH] fix: about sharkey not loading when no connection to sponsors
 json

---
 .../src/server/api/endpoints/sponsors.ts      | 51 +++++++++++--------
 packages/frontend/src/pages/about-sharkey.vue |  2 +-
 2 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/packages/backend/src/server/api/endpoints/sponsors.ts b/packages/backend/src/server/api/endpoints/sponsors.ts
index 79785673aa..50e1c594f2 100644
--- a/packages/backend/src/server/api/endpoints/sponsors.ts
+++ b/packages/backend/src/server/api/endpoints/sponsors.ts
@@ -1,20 +1,20 @@
 import { Inject, Injectable } from '@nestjs/common';
+import * as Redis from 'ioredis';
 import { Endpoint } from '@/server/api/endpoint-base.js';
 import { DI } from '@/di-symbols.js';
-import * as Redis from 'ioredis';
 
 export const meta = {
-	tags: ["meta"],
-	description: "Get Sharkey GH Sponsors",
+	tags: ['meta'],
+	description: 'Get Sharkey GH Sponsors',
 
 	requireCredential: false,
 	requireCredentialPrivateMode: false,
 } as const;
 
 export const paramDef = {
-	type: "object",
+	type: 'object',
 	properties: {
-		forceUpdate: { type: "boolean", default: false },
+		forceUpdate: { type: 'boolean', default: false },
 	},
 	required: [],
 } as const;
@@ -25,22 +25,29 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
         @Inject(DI.redis) private redisClient: Redis.Redis,
 	) {
 		super(meta, paramDef, async (ps, me) => {
-            let sponsors;
-            const cachedSponsors = await this.redisClient.get("sponsors");
-            if (!ps.forceUpdate && cachedSponsors) {
-                sponsors = JSON.parse(cachedSponsors);
-            } else {
-                AbortSignal.timeout ??= function timeout(ms) {
-                    const ctrl = new AbortController();
-                    setTimeout(() => ctrl.abort(), ms);
-                    return ctrl.signal;
-                };
+			let sponsors;
+			const cachedSponsors = await this.redisClient.get('sponsors');
+			if (!ps.forceUpdate && cachedSponsors) {
+				sponsors = JSON.parse(cachedSponsors);
+			} else {
+				AbortSignal.timeout ??= function timeout(ms) {
+					const ctrl = new AbortController();
+					setTimeout(() => ctrl.abort(), ms);
+					return ctrl.signal;
+				};
+
+				try {
+					sponsors = await fetch('https://kaifa.ch/transfem-sponsors.json', { signal: AbortSignal.timeout(2000) })
+						.then((response) => response.json());
 
-                sponsors = await fetch("https://kaifa.ch/transfem-sponsors.json", { signal: AbortSignal.timeout(2000) })
-                    .then((response) => response.json());
-                await this.redisClient.set("sponsors", JSON.stringify(sponsors), "EX", 3600);
-            }
-            return { sponsor_data: sponsors['sponsors'] };
-        });
-    }
+					await this.redisClient.set('sponsors', JSON.stringify(sponsors), 'EX', 3600);
+				} catch (error) {
+					sponsors = {
+						sponsors: [],
+					};
+				}
+			}
+			return { sponsor_data: sponsors['sponsors'] };
+		});
+	}
 }
diff --git a/packages/frontend/src/pages/about-sharkey.vue b/packages/frontend/src/pages/about-sharkey.vue
index 954db9025a..c6d1c46bc5 100644
--- a/packages/frontend/src/pages/about-sharkey.vue
+++ b/packages/frontend/src/pages/about-sharkey.vue
@@ -121,7 +121,7 @@ SPDX-License-Identifier: AGPL-3.0-only
 						</a>
 					</div>
 				</FormSection>
-				<FormSection>
+				<FormSection v-if="sponsors[0].length > 0">
 					<template #label>Our lovely Sponsors</template>
 					<div :class="$style.contributors">
 						<span
-- 
GitLab