mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-13 17:05:47 +01:00
⚡ Improve Calendar module error handling
This commit is contained in:
@@ -6,18 +6,18 @@ import { Config } from '../../../tools/types';
|
|||||||
|
|
||||||
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// Parse req.body as a ServiceItem
|
// Parse req.body as a ServiceItem
|
||||||
const serviceId = req.body;
|
const { id } = req.body;
|
||||||
|
const { type } = req.query;
|
||||||
const configName = getCookie('config-name', { req });
|
const configName = getCookie('config-name', { req });
|
||||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
||||||
// Find service with serviceId in config
|
// Find service with serviceId in config
|
||||||
const service = config.services.find((service) => service.id === serviceId);
|
const service = config.services.find((service) => service.id === id);
|
||||||
if (!service) {
|
if (!service) {
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
message: 'Missing service',
|
message: 'Missing service',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const { type } = req.query;
|
|
||||||
|
|
||||||
const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString();
|
const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString();
|
||||||
const lastMonth = new Date(new Date().setMonth(new Date().getMonth() - 2)).toISOString();
|
const lastMonth = new Date(new Date().setMonth(new Date().getMonth() - 2)).toISOString();
|
||||||
@@ -62,10 +62,10 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
origin = origin.slice(0, -1);
|
origin = origin.slice(0, -1);
|
||||||
}
|
}
|
||||||
const pined = `${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`;
|
const pined = `${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`;
|
||||||
const data = await axios.get(
|
return axios
|
||||||
`${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`
|
.get(`${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`)
|
||||||
);
|
.then((response) => res.status(200).json(response.data))
|
||||||
return res.status(200).json(data.data);
|
.catch((e) => res.status(500).json(e));
|
||||||
// // Make a request to the URL
|
// // Make a request to the URL
|
||||||
// const response = await axios.get(url);
|
// const response = await axios.get(url);
|
||||||
// // Return the response
|
// // Return the response
|
||||||
|
|||||||
Reference in New Issue
Block a user