aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2023-03-14 08:50:44 +0100
committerGitHub <noreply@github.com>2023-03-14 08:50:44 +0100
commite72ace5a506904a67290e347e962ddf930d2b9f9 (patch)
tree08af8cb7b20e9911c4962910024ba2ba70645d92
parent2b02a9b98cfc93a01b52ad6cb893e3d089fec472 (diff)
downloadPeerTube-e72ace5a506904a67290e347e962ddf930d2b9f9.tar.gz
PeerTube-e72ace5a506904a67290e347e962ddf930d2b9f9.tar.zst
PeerTube-e72ace5a506904a67290e347e962ddf930d2b9f9.zip
Handle redis disconnection gracefully (#5599)
* feat(server/api/contact): handle redis disconnection * feat(server/api/metrics): handle metrics disabled
-rw-r--r--server/controllers/api/metrics.ts5
-rw-r--r--server/controllers/api/server/contact.ts7
2 files changed, 11 insertions, 1 deletions
diff --git a/server/controllers/api/metrics.ts b/server/controllers/api/metrics.ts
index 578b023a1..f66173875 100644
--- a/server/controllers/api/metrics.ts
+++ b/server/controllers/api/metrics.ts
@@ -2,6 +2,7 @@ import express from 'express'
2import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics' 2import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics'
3import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' 3import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models'
4import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares' 4import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares'
5import { CONFIG } from '@server/initializers/config'
5 6
6const metricsRouter = express.Router() 7const metricsRouter = express.Router()
7 8
@@ -19,6 +20,10 @@ export {
19// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
20 21
21function addPlaybackMetric (req: express.Request, res: express.Response) { 22function addPlaybackMetric (req: express.Request, res: express.Response) {
23 if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) {
24 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
25 }
26
22 const body: PlaybackMetricCreate = req.body 27 const body: PlaybackMetricCreate = req.body
23 28
24 OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body) 29 OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body)
diff --git a/server/controllers/api/server/contact.ts b/server/controllers/api/server/contact.ts
index 09ff50f69..56596bea5 100644
--- a/server/controllers/api/server/contact.ts
+++ b/server/controllers/api/server/contact.ts
@@ -1,3 +1,4 @@
1import { logger } from '@server/helpers/logger'
1import express from 'express' 2import express from 'express'
2import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 3import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
3import { ContactForm } from '../../../../shared/models/server' 4import { ContactForm } from '../../../../shared/models/server'
@@ -17,7 +18,11 @@ async function contactAdministrator (req: express.Request, res: express.Response
17 18
18 Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body) 19 Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body)
19 20
20 await Redis.Instance.setContactFormIp(req.ip) 21 try {
22 await Redis.Instance.setContactFormIp(req.ip)
23 } catch (err) {
24 logger.error(err)
25 }
21 26
22 return res.status(HttpStatusCode.NO_CONTENT_204).end() 27 return res.status(HttpStatusCode.NO_CONTENT_204).end()
23} 28}