mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-05 23:43:57 +00:00
884ab0b67b
* refactor: add revision number to rundown * chore: migrate query
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import axios, { AxiosError } from 'axios';
|
|
import { LogLevel } from 'ontime-types';
|
|
import { generateId, millisToString } from 'ontime-utils';
|
|
|
|
import { ontimeQueryClient } from '../queryClient';
|
|
import { addLog } from '../stores/logger';
|
|
import { nowInMillis } from '../utils/time';
|
|
|
|
export function maybeAxiosError(error: unknown) {
|
|
if (axios.isAxiosError(error)) {
|
|
const statusText = (error as AxiosError).response?.statusText ?? '';
|
|
let data = (error as AxiosError).response?.data ?? '';
|
|
if (typeof data === 'object') {
|
|
if ('message' in data) {
|
|
data = JSON.stringify(data.message);
|
|
} else {
|
|
data = JSON.stringify(data);
|
|
}
|
|
}
|
|
return `${statusText}: ${data}`;
|
|
} else {
|
|
if (typeof error !== 'string') {
|
|
return JSON.stringify(error);
|
|
}
|
|
return error;
|
|
}
|
|
}
|
|
|
|
export function logAxiosError(prepend: string, error: unknown) {
|
|
const message = `${prepend}: ${maybeAxiosError(error)}`;
|
|
|
|
addLog({
|
|
id: generateId(),
|
|
origin: 'SERVER',
|
|
time: millisToString(nowInMillis()),
|
|
level: LogLevel.Error,
|
|
text: message,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Utility function invalidates react-query caches
|
|
*/
|
|
export async function invalidateAllCaches() {
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['project'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['aliases'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['userFields'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['rundown'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['appinfo'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['oscSettings'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['appSettings'] });
|
|
await ontimeQueryClient.invalidateQueries({ queryKey: ['viewSettings'] });
|
|
}
|