mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-05 07:28:01 +00:00
21 lines
641 B
TypeScript
21 lines
641 B
TypeScript
import axios, { AxiosError } from 'axios';
|
|
import { LogLevel } from 'ontime-types';
|
|
import { generateId, millisToString } from 'ontime-utils';
|
|
|
|
import { addLog } from '../stores/logger';
|
|
import { nowInMillis } from '../utils/time';
|
|
|
|
export function logAxiosError(prepend: string, error: unknown) {
|
|
const message = axios.isAxiosError(error)
|
|
? `${prepend} ${(error as AxiosError).response?.statusText ?? ''}: ${(error as AxiosError).response?.data ?? ''}`
|
|
: `${prepend}: ${error}`;
|
|
|
|
addLog({
|
|
id: generateId(),
|
|
origin: 'SERVER',
|
|
time: millisToString(nowInMillis()),
|
|
level: LogLevel.Error,
|
|
text: message,
|
|
});
|
|
}
|