mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
refactor: better errors (#590)
* refactor: improve error messages from server
This commit is contained in:
@@ -149,7 +149,7 @@ export const postAliases = async (req, res) => {
|
||||
await DataProvider.setAliases(newAliases);
|
||||
res.status(200).send(newAliases);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -172,7 +172,7 @@ export const postUserFields = async (req, res) => {
|
||||
await DataProvider.setUserFields(newData);
|
||||
res.status(200).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -235,7 +235,7 @@ export const postSettings = async (req, res) => {
|
||||
await DataProvider.setSettings(newData);
|
||||
res.status(200).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -270,7 +270,7 @@ export const postViewSettings = async (req, res) => {
|
||||
await DataProvider.setViewSettings(newData);
|
||||
res.status(200).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -298,7 +298,7 @@ export const postOscSubscriptions = async (req, res) => {
|
||||
|
||||
res.send(oscSettings).status(200);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -319,7 +319,7 @@ export const postOSC = async (req, res) => {
|
||||
|
||||
res.send(oscSettings).status(200);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -348,7 +348,7 @@ export async function patchPartialProjectFile(req, res) {
|
||||
}
|
||||
res.status(200).send();
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,6 +409,6 @@ export const postNew: RequestHandler = async (req, res) => {
|
||||
await deleteAllEvents();
|
||||
res.status(201).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,14 +13,14 @@ export const pbStart = async (req, res) => {
|
||||
const { eventId, eventIndex } = req.query;
|
||||
if (eventId) {
|
||||
const success = PlaybackService.startById(eventId);
|
||||
success ? res.sendStatus(202) : res.status(400).send('Invalid event ID');
|
||||
success ? res.sendStatus(202) : res.status(400).send({ message: 'Invalid event ID' });
|
||||
} else if (eventIndex) {
|
||||
const index = Number(eventIndex);
|
||||
if (!isNaN(index)) {
|
||||
const success = PlaybackService.startByIndex(eventIndex - 1);
|
||||
success ? res.sendStatus(202) : res.status(400).send('Invalid event index');
|
||||
success ? res.sendStatus(202) : res.status(400).send({ message: 'Invalid event index' });
|
||||
} else {
|
||||
res.status(400).send('Invalid event index');
|
||||
res.status(400).send({ message: 'Invalid event index' });
|
||||
}
|
||||
} else {
|
||||
PlaybackService.start();
|
||||
@@ -69,17 +69,17 @@ export const pbLoad = async (req, res) => {
|
||||
const { eventId, eventIndex } = req.query;
|
||||
if (eventId) {
|
||||
const success = PlaybackService.loadById(eventId);
|
||||
success ? res.sendStatus(202) : res.status(400).send('Invalid event ID');
|
||||
success ? res.sendStatus(202) : res.status(400).send({ message: 'Invalid event ID' });
|
||||
} else if (eventIndex) {
|
||||
const index = Number(eventIndex);
|
||||
if (!isNaN(index)) {
|
||||
const success = PlaybackService.loadByIndex(eventIndex - 1);
|
||||
success ? res.sendStatus(202) : res.status(400).send('Invalid event index');
|
||||
success ? res.sendStatus(202) : res.status(400).send({ message: 'Invalid event index' });
|
||||
} else {
|
||||
res.status(400).send('Invalid event index');
|
||||
res.status(400).send({ message: 'Invalid event index' });
|
||||
}
|
||||
} else {
|
||||
res.status(400).send('No event given');
|
||||
res.status(400).send({ message: 'No event given' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,6 @@ export const postProject: RequestHandler = async (req, res) => {
|
||||
const newData = await DataProvider.setProjectData(newEvent);
|
||||
res.status(200).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@ export const rundownPost: RequestHandler = async (req, res) => {
|
||||
const newEvent = await addEvent(req.body);
|
||||
res.status(201).send(newEvent);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ export const rundownPut: RequestHandler = async (req, res) => {
|
||||
const event = await editEvent(req.body);
|
||||
res.status(200).send(event);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ export const rundownReorder: RequestHandler = async (req, res) => {
|
||||
const event = await reorderEvent(eventId, from, to);
|
||||
res.status(200).send(event);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -72,7 +72,7 @@ export const rundownSwap: RequestHandler = async (req, res) => {
|
||||
await swapEvents(from, to);
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ export const rundownApplyDelay: RequestHandler = async (req, res) => {
|
||||
await applyDelay(req.params.eventId);
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -94,7 +94,7 @@ export const deleteEventById: RequestHandler = async (req, res) => {
|
||||
await deleteEvent(req.params.eventId);
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -105,6 +105,6 @@ export const rundownDelete: RequestHandler = async (req, res) => {
|
||||
await deleteAllEvents();
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
res.status(400).send(error);
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user