mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
refactor: better errors (#590)
* refactor: improve error messages from server
This commit is contained in:
@@ -11,7 +11,6 @@ export function maybeAxiosError(error: unknown) {
|
|||||||
const statusText = (error as AxiosError).response?.statusText ?? '';
|
const statusText = (error as AxiosError).response?.statusText ?? '';
|
||||||
let data = (error as AxiosError).response?.data ?? '';
|
let data = (error as AxiosError).response?.data ?? '';
|
||||||
if (typeof data === 'object') {
|
if (typeof data === 'object') {
|
||||||
// TODO: use error instead, when migrated
|
|
||||||
if ('message' in data) {
|
if ('message' in data) {
|
||||||
data = JSON.stringify(data.message);
|
data = JSON.stringify(data.message);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export const useEventAction = () => {
|
|||||||
// @ts-expect-error -- we know that the object is well formed now
|
// @ts-expect-error -- we know that the object is well formed now
|
||||||
await _addEventMutation.mutateAsync(newEvent);
|
await _addEventMutation.mutateAsync(newEvent);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logAxiosError('Error fetching data', error);
|
logAxiosError('Failed adding event', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[_addEventMutation, defaultPublic, queryClient, startTimeIsLastEnd],
|
[_addEventMutation, defaultPublic, queryClient, startTimeIsLastEnd],
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export class DataProvider {
|
|||||||
|
|
||||||
static async clearRundown() {
|
static async clearRundown() {
|
||||||
data.rundown = [];
|
data.rundown = [];
|
||||||
// @ts-expect-error -- not sure how to type, this is library side
|
|
||||||
await db.write();
|
await db.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +99,6 @@ export class DataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async persist() {
|
static async persist() {
|
||||||
// @ts-expect-error -- not sure how to type, this is library side
|
|
||||||
await db.write();
|
await db.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ export const postAliases = async (req, res) => {
|
|||||||
await DataProvider.setAliases(newAliases);
|
await DataProvider.setAliases(newAliases);
|
||||||
res.status(200).send(newAliases);
|
res.status(200).send(newAliases);
|
||||||
} catch (error) {
|
} 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);
|
await DataProvider.setUserFields(newData);
|
||||||
res.status(200).send(newData);
|
res.status(200).send(newData);
|
||||||
} catch (error) {
|
} 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);
|
await DataProvider.setSettings(newData);
|
||||||
res.status(200).send(newData);
|
res.status(200).send(newData);
|
||||||
} catch (error) {
|
} 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);
|
await DataProvider.setViewSettings(newData);
|
||||||
res.status(200).send(newData);
|
res.status(200).send(newData);
|
||||||
} catch (error) {
|
} 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);
|
res.send(oscSettings).status(200);
|
||||||
} catch (error) {
|
} 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);
|
res.send(oscSettings).status(200);
|
||||||
} catch (error) {
|
} 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();
|
res.status(200).send();
|
||||||
} catch (error) {
|
} 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();
|
await deleteAllEvents();
|
||||||
res.status(201).send(newData);
|
res.status(201).send(newData);
|
||||||
} catch (error) {
|
} 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;
|
const { eventId, eventIndex } = req.query;
|
||||||
if (eventId) {
|
if (eventId) {
|
||||||
const success = PlaybackService.startById(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) {
|
} else if (eventIndex) {
|
||||||
const index = Number(eventIndex);
|
const index = Number(eventIndex);
|
||||||
if (!isNaN(index)) {
|
if (!isNaN(index)) {
|
||||||
const success = PlaybackService.startByIndex(eventIndex - 1);
|
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 {
|
} else {
|
||||||
res.status(400).send('Invalid event index');
|
res.status(400).send({ message: 'Invalid event index' });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PlaybackService.start();
|
PlaybackService.start();
|
||||||
@@ -69,17 +69,17 @@ export const pbLoad = async (req, res) => {
|
|||||||
const { eventId, eventIndex } = req.query;
|
const { eventId, eventIndex } = req.query;
|
||||||
if (eventId) {
|
if (eventId) {
|
||||||
const success = PlaybackService.loadById(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) {
|
} else if (eventIndex) {
|
||||||
const index = Number(eventIndex);
|
const index = Number(eventIndex);
|
||||||
if (!isNaN(index)) {
|
if (!isNaN(index)) {
|
||||||
const success = PlaybackService.loadByIndex(eventIndex - 1);
|
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 {
|
} else {
|
||||||
res.status(400).send('Invalid event index');
|
res.status(400).send({ message: 'Invalid event index' });
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
const newData = await DataProvider.setProjectData(newEvent);
|
||||||
res.status(200).send(newData);
|
res.status(200).send(newData);
|
||||||
} catch (error) {
|
} 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);
|
const newEvent = await addEvent(req.body);
|
||||||
res.status(201).send(newEvent);
|
res.status(201).send(newEvent);
|
||||||
} catch (error) {
|
} 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);
|
const event = await editEvent(req.body);
|
||||||
res.status(200).send(event);
|
res.status(200).send(event);
|
||||||
} catch (error) {
|
} 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);
|
const event = await reorderEvent(eventId, from, to);
|
||||||
res.status(200).send(event);
|
res.status(200).send(event);
|
||||||
} catch (error) {
|
} 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);
|
await swapEvents(from, to);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
} catch (error) {
|
} 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);
|
await applyDelay(req.params.eventId);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
} catch (error) {
|
} 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);
|
await deleteEvent(req.params.eventId);
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
} catch (error) {
|
} 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();
|
await deleteAllEvents();
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(400).send(error);
|
res.status(400).send({ message: error.toString() });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ async function loadDb() {
|
|||||||
return { db, data };
|
return { db, data };
|
||||||
}
|
}
|
||||||
|
|
||||||
export let db = {};
|
export let db = {} as Low<DatabaseModel>;
|
||||||
export let data = {} as DatabaseModel;
|
export let data = {} as DatabaseModel;
|
||||||
export const dbLoadingProcess = loadDb();
|
export const dbLoadingProcess = loadDb();
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ export function updateTimer(affectedIds?: string[]) {
|
|||||||
export async function addEvent(eventData: Partial<OntimeEvent> | Partial<OntimeDelay> | Partial<OntimeBlock>) {
|
export async function addEvent(eventData: Partial<OntimeEvent> | Partial<OntimeDelay> | Partial<OntimeBlock>) {
|
||||||
const numEvents = DataProvider.getRundownLength();
|
const numEvents = DataProvider.getRundownLength();
|
||||||
if (numEvents > MAX_EVENTS) {
|
if (numEvents > MAX_EVENTS) {
|
||||||
throw new Error(`ERROR: Reached limit number of ${MAX_EVENTS} events`);
|
throw new Error(`Reached limit number of ${MAX_EVENTS} events`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let newEvent: Partial<OntimeBaseEvent> = {};
|
let newEvent: Partial<OntimeBaseEvent> = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user