Skip to content

Commit f7987f4

Browse files
committed
Add detailed logging for API calls
1 parent 3b80481 commit f7987f4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/components/modals/AddStockModal.jsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, useState } from 'react';
1+
import { Fragment, useState, useEffect } from 'react';
22
import { Dialog, Transition } from '@headlessui/react';
33
import { XMarkIcon } from '@heroicons/react/24/outline';
44
import { TextInput, NumberInput, Button } from '@tremor/react';
@@ -17,6 +17,11 @@ export default function AddStockModal({ open, setOpen, onStockAdded }) {
1717
target_price: ''
1818
});
1919

20+
// Log API URL on component mount
21+
useEffect(() => {
22+
console.log('API Base URL:', API_BASE_URL);
23+
}, []);
24+
2025
const handleChange = (e) => {
2126
const { name, value } = e.target;
2227
setFormData(prev => ({
@@ -37,13 +42,18 @@ export default function AddStockModal({ open, setOpen, onStockAdded }) {
3742
throw new Error('Please fill in all required fields');
3843
}
3944

40-
const response = await axios.post(`${API_BASE_URL}/stocks`, {
45+
const requestData = {
4146
name: formData.name,
4247
ticker: formData.ticker.toUpperCase(),
4348
shares: parseFloat(formData.shares),
4449
buy_price: parseFloat(formData.buy_price),
4550
target_price: parseFloat(formData.target_price || formData.buy_price)
46-
});
51+
};
52+
53+
console.log('Making API request to:', `${API_BASE_URL}/stocks`);
54+
console.log('Request data:', requestData);
55+
56+
const response = await axios.post(`${API_BASE_URL}/stocks`, requestData);
4757

4858
console.log('Stock added successfully:', response.data);
4959

@@ -62,7 +72,12 @@ export default function AddStockModal({ open, setOpen, onStockAdded }) {
6272
onStockAdded(response.data);
6373
}
6474
} catch (error) {
65-
console.error('Error adding stock:', error);
75+
console.error('Error details:', {
76+
message: error.message,
77+
response: error.response?.data,
78+
status: error.response?.status,
79+
apiUrl: API_BASE_URL
80+
});
6681
setError(error.response?.data?.error || error.message || 'Failed to add stock');
6782
} finally {
6883
setLoading(false);

0 commit comments

Comments
 (0)