Skip to content

Commit

Permalink
πŸ”Š More detailed logging in the client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario-SO committed Jan 20, 2025
1 parent fd92ff3 commit 8a4f547
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
14 changes: 13 additions & 1 deletion packages/app/lib/actions/videoUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ import { videoUpload } from '../services/videoUploadService';

export const videoUploadAction = async ({ data }: { data: FormData }) => {
try {
console.log('πŸ“€ Starting video upload action');
console.log('πŸ“ FormData contents:', {
fileName: (data.get('file') as File)?.name,
directory: data.get('directory'),
fileSize: (data.get('file') as File)?.size,
});

const res = await videoUpload({
data,
});
console.log('✨ Video upload action completed successfully');
revalidatePath('/studio');

return res;
} catch (e) {
console.error('Error uploading video action:', e);
console.error('πŸ’₯ Error in video upload action:', {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined
});
throw e;
}
};
52 changes: 39 additions & 13 deletions packages/app/lib/services/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,45 @@
import { auth } from '@/auth';

export const fetchClient = async (url: string, options: RequestInit = {}) => {
const session = await auth();
const headers = new Headers(options.headers);
try {
console.log('🌐 Fetch client starting request to:', url);
const session = await auth();
const headers = new Headers(options.headers);

if (session?.accessToken) {
console.log('πŸ”‘ Adding auth token to request');
headers.set('Authorization', `Bearer ${session.accessToken}`);
} else {
console.warn('⚠️ No auth token available for request');
}
if (session?.accessToken) {
console.log('πŸ” Adding auth token to request');
headers.set('Authorization', `Bearer ${session.accessToken}`);
} else {
console.warn('⚠️ No auth token available for request');
}

console.log('πŸ“‘ Making request with headers:', {
method: options.method,
headers: Object.fromEntries(headers.entries()),
hasBody: !!options.body,
bodyType: options.body instanceof FormData ? 'FormData' : typeof options.body,
});

const response = await fetch(url, {
...options,
headers,
});

console.log('🌐 Making request to:', url);
return fetch(url, {
...options,
headers,
});
console.log('πŸ“₯ Received response:', {
status: response.status,
statusText: response.statusText,
headers: Object.fromEntries(response.headers.entries()),
});

return response;
} catch (e) {
console.error('πŸ’₯ Error in fetch client:', {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined,
url,
method: options.method,
});
throw e;
}
};
27 changes: 21 additions & 6 deletions packages/app/lib/services/videoUploadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ export const videoUpload = async ({
data: FormData;
}): Promise<string> => {
try {
console.log('πŸŽ₯ Starting video upload to:', `${apiUrl()}/upload`);
const response = await fetchClient(`${apiUrl()}/upload`, {
const uploadUrl = `${apiUrl()}/upload`;
console.log('πŸŽ₯ Starting video upload service call:', {
url: uploadUrl,
fileSize: (data.get('file') as File)?.size,
directory: data.get('directory'),
});

console.log('πŸ”‘ Checking auth headers...');
const response = await fetchClient(uploadUrl, {
method: 'POST',
cache: 'no-cache',
headers: {},
Expand All @@ -17,19 +24,27 @@ export const videoUpload = async ({

if (!response.ok) {
const errorText = await response.text();
console.error('❌ Video upload failed:', {
console.error('❌ Video upload service failed:', {
status: response.status,
statusText: response.statusText,
error: errorText
error: errorText,
headers: Object.fromEntries(response.headers.entries()),
});
throw new Error(`Error uploading video: ${errorText}`);
}

const result = await response.json();
console.log('βœ… Video upload successful:', result);
console.log('βœ… Video upload service successful:', {
result,
responseHeaders: Object.fromEntries(response.headers.entries()),
});
return result.data;
} catch (e) {
console.error('❌ Error in upload video service:', e);
console.error('πŸ’₯ Error in video upload service:', {
error: e,
message: e instanceof Error ? e.message : 'Unknown error',
stack: e instanceof Error ? e.stack : undefined,
});
throw e;
}
};

0 comments on commit 8a4f547

Please sign in to comment.