mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 19:10:47 +02:00
Chore/v2/transforms as root (#5868)
Any task that changes file type or produces more/fewer files than the input are now consumed as root files not incremented versions of the input.
This commit is contained in:
@@ -34,6 +34,46 @@ export const createStandardErrorHandler = (fallbackMessage: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a 422 response, extracts errored file IDs from the payload (JSON or UUID regex),
|
||||
* and marks them in the UI. Returns true if IDs were found and handled, false otherwise.
|
||||
*/
|
||||
export const handle422Error = async (
|
||||
error: any,
|
||||
markFileError: (fileId: string) => void
|
||||
): Promise<boolean> => {
|
||||
const status = error?.response?.status;
|
||||
if (typeof status !== 'number' || status !== 422) return false;
|
||||
|
||||
const payload = error?.response?.data;
|
||||
let parsed: unknown = payload;
|
||||
|
||||
if (typeof payload === 'string') {
|
||||
try { parsed = JSON.parse(payload); } catch { parsed = payload; }
|
||||
} else if (payload && typeof (payload as Blob).text === 'function') {
|
||||
const text = await (payload as Blob).text();
|
||||
try { parsed = JSON.parse(text); } catch { parsed = text; }
|
||||
}
|
||||
|
||||
let ids: string[] | undefined = Array.isArray((parsed as { errorFileIds?: unknown })?.errorFileIds)
|
||||
? (parsed as { errorFileIds: string[] }).errorFileIds
|
||||
: undefined;
|
||||
|
||||
if (!ids && typeof parsed === 'string') {
|
||||
const match = parsed.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/g);
|
||||
if (match && match.length > 0) ids = Array.from(new Set(match));
|
||||
}
|
||||
|
||||
if (ids && ids.length > 0) {
|
||||
for (const id of ids) {
|
||||
try { markFileError(id); } catch (_e) { void _e; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles password-related errors with status code checking
|
||||
* @param error - The error object from axios
|
||||
|
||||
Reference in New Issue
Block a user