mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 07:13:37 +01:00
Error handling for queries.
This commit is contained in:
parent
cebd3fd924
commit
cb48acde55
@ -4,7 +4,7 @@ import { formatNumber } from '../../lib/format';
|
||||
import styles from './MetricCard.module.css';
|
||||
|
||||
const MetricCard = ({ value = 0, label, format = formatNumber }) => {
|
||||
const props = useSpring({ x: value, from: { x: 0 } });
|
||||
const props = useSpring({ x: Number(value) || 0, from: { x: 0 } });
|
||||
|
||||
return (
|
||||
<div className={styles.card}>
|
||||
|
@ -299,7 +299,7 @@ export function getMetrics(website_id, start_at, end_at) {
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve({});
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
}
|
||||
|
||||
export function getPageviews(
|
||||
@ -346,7 +346,7 @@ export function getPageviews(
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve([]);
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
}
|
||||
|
||||
export function getRankings(website_id, start_at, end_at, type, table, domain) {
|
||||
@ -388,7 +388,7 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve([]);
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
}
|
||||
|
||||
export function getActiveVisitors(website_id) {
|
||||
@ -421,7 +421,7 @@ export function getActiveVisitors(website_id) {
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve([]);
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
}
|
||||
|
||||
export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit = 'day') {
|
||||
@ -465,5 +465,5 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve([]);
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
}
|
||||
|
@ -3,11 +3,14 @@ import { ok } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id, start_at, end_at } = req.query;
|
||||
const websiteId = +id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
const metrics = await getMetrics(+id, new Date(+start_at), new Date(+end_at));
|
||||
const metrics = await getMetrics(websiteId, startDate, endDate);
|
||||
|
||||
const stats = Object.keys(metrics[0]).reduce((obj, key) => {
|
||||
obj[key] = +metrics[0][key];
|
||||
obj[key] = Number(metrics[0][key]) || 0;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user