Add metadata Pinia store for ExifTool queue preview reads.

Introduce preview entry types, resolveErrorMessage, and nullcart-style resolveAxiosErrorMessage for upcoming upload API errors.
This commit is contained in:
2026-10-13 22:18:48 +02:00
parent e89f76a673
commit 321c67fa3d
4 changed files with 130 additions and 18 deletions
@@ -1,23 +1,40 @@
import axios from 'axios';
import { isAxiosError } from 'axios';
import { resolveErrorMessage } from '@/utils/resolveErrorMessage';
export function resolveAxiosErrorMessage(error: unknown, fallback = 'Request failed'): string {
if (axios.isAxiosError(error)) {
const data = error.response?.data;
if (typeof data === 'object' && data !== null && 'message' in data) {
const message = (data as { message: unknown }).message;
if (typeof message === 'string') {
return message;
}
if (Array.isArray(message)) {
return message.map(String).join(', ');
}
const getAxiosErrorResponseMessage = (data: unknown): string | null => {
if (typeof data === 'string') {
return data;
}
if (typeof data !== 'object' || data === null || !('message' in data)) {
return null;
}
const { message } = data;
if (typeof message === 'string') {
return message;
}
if (Array.isArray(message)) {
const texts = message.filter((item): item is string => typeof item === 'string');
if (texts.length === 1) {
return texts[0];
}
if (error.message) {
return error.message;
if (texts.length > 1) {
return texts.join(', ');
}
}
if (error instanceof Error) {
return error.message;
return null;
};
export const resolveAxiosErrorMessage = (error: unknown, fallback: string): string => {
if (!isAxiosError(error) || !error.response) {
return resolveErrorMessage(error, fallback);
}
return fallback;
}
return getAxiosErrorResponseMessage(error.response.data) ?? fallback;
};
@@ -0,0 +1,7 @@
export function resolveErrorMessage(error: unknown, fallback = 'Something went wrong'): string {
if (error instanceof Error && error.message.length > 0) {
return error.message;
}
return fallback;
}