mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 06:29:07 +00:00
refactor: simplify handling axios errors
This commit is contained in:
@@ -5,15 +5,18 @@ import { generateId, millisToString } from 'ontime-utils';
|
|||||||
import { addLog } from '../stores/logger';
|
import { addLog } from '../stores/logger';
|
||||||
import { nowInMillis } from '../utils/time';
|
import { nowInMillis } from '../utils/time';
|
||||||
|
|
||||||
export function logAxiosError(prepend: string, error: unknown) {
|
export function maybeAxiosError(error: unknown) {
|
||||||
let message;
|
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
const statusText = (error as AxiosError).response?.statusText ?? '';
|
const statusText = (error as AxiosError).response?.statusText ?? '';
|
||||||
const data = (error as AxiosError).response?.data ?? '';
|
const data = (error as AxiosError).response?.data ?? '';
|
||||||
message = `${prepend} ${statusText}: ${data}`;
|
return `${statusText}: ${data}`;
|
||||||
} else {
|
} else {
|
||||||
message = `${prepend}: ${error}`;
|
return error as string;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function logAxiosError(prepend: string, error: unknown) {
|
||||||
|
const message = `${prepend}: ${maybeAxiosError(error)}`;
|
||||||
|
|
||||||
addLog({
|
addLog({
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
|
|||||||
Reference in New Issue
Block a user