Handle redis disconnection gracefully (#5599)

* feat(server/api/contact): handle redis disconnection

* feat(server/api/metrics): handle metrics disabled
This commit is contained in:
kontrollanten 2023-03-14 08:50:44 +01:00 committed by GitHub
parent 2b02a9b98c
commit e72ace5a50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import express from 'express'
import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics'
import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models'
import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares'
import { CONFIG } from '@server/initializers/config'
const metricsRouter = express.Router()
@ -19,6 +20,10 @@ export {
// ---------------------------------------------------------------------------
function addPlaybackMetric (req: express.Request, res: express.Response) {
if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) {
return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
}
const body: PlaybackMetricCreate = req.body
OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body)

View File

@ -1,3 +1,4 @@
import { logger } from '@server/helpers/logger'
import express from 'express'
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
import { ContactForm } from '../../../../shared/models/server'
@ -17,7 +18,11 @@ async function contactAdministrator (req: express.Request, res: express.Response
Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body)
await Redis.Instance.setContactFormIp(req.ip)
try {
await Redis.Instance.setContactFormIp(req.ip)
} catch (err) {
logger.error(err)
}
return res.status(HttpStatusCode.NO_CONTENT_204).end()
}