1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/routes/client-api/metrics.js
2021-01-21 15:53:24 +01:00

34 lines
920 B
JavaScript

'use strict';
const Controller = require('../controller');
class ClientMetricsController extends Controller {
constructor({ clientMetricsService }, getLogger) {
super();
this.logger = getLogger('/api/client/metrics');
this.metrics = clientMetricsService;
this.post('/', this.registerMetrics);
}
async registerMetrics(req, res) {
const data = req.body;
const clientIp = req.ip;
try {
await this.metrics.registerClientMetrics(data, clientIp);
return res.status(202).end();
} catch (e) {
this.logger.warn('Failed to store metrics', e);
switch (e.name) {
case 'ValidationError':
return res.status(400).end();
default:
return res.status(500).end();
}
}
}
}
module.exports = ClientMetricsController;