typescript-typenfehler behoben.. npm run lint läuft nun fehlerfrei durch.
This commit is contained in:
@@ -62,10 +62,12 @@ export async function likePhoto(id: number): Promise<number> {
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
let payload: any = null;
|
||||
let payload: unknown = null;
|
||||
try {
|
||||
payload = await res.clone().json();
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
console.warn('Like photo: failed to parse error payload', error);
|
||||
}
|
||||
|
||||
if (res.status === 419) {
|
||||
const error: UploadError = new Error('CSRF token mismatch. Please refresh the page and try again.');
|
||||
@@ -75,12 +77,13 @@ export async function likePhoto(id: number): Promise<number> {
|
||||
}
|
||||
|
||||
const error: UploadError = new Error(
|
||||
payload?.error?.message ?? `Like failed: ${res.status}`
|
||||
(payload as { error?: { message?: string } } | null)?.error?.message ?? `Like failed: ${res.status}`
|
||||
);
|
||||
error.code = payload?.error?.code ?? 'like_failed';
|
||||
error.code = (payload as { error?: { code?: string } } | null)?.error?.code ?? 'like_failed';
|
||||
error.status = res.status;
|
||||
if (payload?.error?.meta) {
|
||||
error.meta = payload.error.meta as Record<string, unknown>;
|
||||
const meta = (payload as { error?: { meta?: Record<string, unknown> } } | null)?.error?.meta;
|
||||
if (meta) {
|
||||
error.meta = meta;
|
||||
}
|
||||
|
||||
throw error;
|
||||
@@ -114,7 +117,7 @@ export async function uploadPhoto(
|
||||
const url = `/api/v1/events/${encodeURIComponent(eventToken)}/upload`;
|
||||
const headers = getCsrfHeaders();
|
||||
|
||||
const attemptUpload = (attempt: number): Promise<any> =>
|
||||
const attemptUpload = (): Promise<Record<string, unknown>> =>
|
||||
new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, true);
|
||||
@@ -139,7 +142,7 @@ export async function uploadPhoto(
|
||||
|
||||
xhr.onload = () => {
|
||||
const status = xhr.status;
|
||||
const payload = xhr.response ?? null;
|
||||
const payload = (xhr.response ?? null) as Record<string, unknown> | null;
|
||||
|
||||
if (status >= 200 && status < 300) {
|
||||
resolve(payload);
|
||||
@@ -147,12 +150,13 @@ export async function uploadPhoto(
|
||||
}
|
||||
|
||||
const error: UploadError = new Error(
|
||||
payload?.error?.message ?? `Upload failed: ${status}`
|
||||
(payload as { error?: { message?: string } } | null)?.error?.message ?? `Upload failed: ${status}`
|
||||
);
|
||||
error.code = payload?.error?.code ?? (status === 0 ? 'network_error' : 'upload_failed');
|
||||
error.code = (payload as { error?: { code?: string } } | null)?.error?.code ?? (status === 0 ? 'network_error' : 'upload_failed');
|
||||
error.status = status;
|
||||
if (payload?.error?.meta) {
|
||||
error.meta = payload.error.meta as Record<string, unknown>;
|
||||
const meta = (payload as { error?: { meta?: Record<string, unknown> } } | null)?.error?.meta;
|
||||
if (meta) {
|
||||
error.meta = meta;
|
||||
}
|
||||
reject(error);
|
||||
};
|
||||
@@ -174,8 +178,9 @@ export async function uploadPhoto(
|
||||
|
||||
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
const json = await attemptUpload(attempt + 1);
|
||||
return json?.photo_id ?? json?.id ?? json?.data?.id ?? 0;
|
||||
const json = await attemptUpload();
|
||||
const payload = json as { photo_id?: number; id?: number; data?: { id?: number } };
|
||||
return payload.photo_id ?? payload.id ?? payload.data?.id ?? 0;
|
||||
} catch (error) {
|
||||
const err = error as UploadError;
|
||||
|
||||
@@ -213,13 +218,16 @@ export async function createPhotoShareLink(eventToken: string, photoId: number):
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
let payload: any = null;
|
||||
let payload: unknown = null;
|
||||
try {
|
||||
payload = await res.clone().json();
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
console.warn('Share link error payload parse failed', error);
|
||||
}
|
||||
|
||||
const error: UploadError = new Error(payload?.error?.message ?? 'Share link creation failed');
|
||||
error.code = payload?.error?.code ?? 'share_failed';
|
||||
const errorPayload = payload as { error?: { message?: string; code?: string } } | null;
|
||||
const error: UploadError = new Error(errorPayload?.error?.message ?? 'Share link creation failed');
|
||||
error.code = errorPayload?.error?.code ?? 'share_failed';
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user