Handle redis disconnection gracefully (#5599)
* feat(server/api/contact): handle redis disconnection * feat(server/api/metrics): handle metrics disabled
This commit is contained in:
parent
2b02a9b98c
commit
e72ace5a50
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue