From d950a84e2a1a36c598c27f111cb1fc01bb70076f Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Fri, 9 Feb 2024 19:05:58 +0000 Subject: [PATCH] chore: declutter server logs --- lib/middlewares/populateDeviceId.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/middlewares/populateDeviceId.js b/lib/middlewares/populateDeviceId.js index 4c8913ae..dd2fd9e2 100644 --- a/lib/middlewares/populateDeviceId.js +++ b/lib/middlewares/populateDeviceId.js @@ -4,6 +4,7 @@ const crypto = require('crypto') const logger = require('../logger') function sha256 (buf) { + if (!buf) return null const hash = crypto.createHash('sha256') hash.update(buf) @@ -12,9 +13,10 @@ function sha256 (buf) { const populateDeviceId = function (req, res, next) { const deviceId = _.isFunction(req.connection.getPeerCertificate) - ? sha256(req.connection.getPeerCertificate().raw) + ? sha256(req.connection.getPeerCertificate()?.raw) : null + if (!deviceId) return res.status(500).json({ error: 'Unable to find certificate' }) req.deviceId = deviceId req.deviceTime = req.get('date')