working leantime widget 2
This commit is contained in:
parent
7c8f64a716
commit
3b8520da1f
@ -10,6 +10,9 @@ export async function GET() {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('Fetching status labels for user:', session.user.id);
|
||||
console.log('Using LEANTIME_TOKEN:', process.env.LEANTIME_TOKEN ? 'Present' : 'Missing');
|
||||
|
||||
const response = await fetch('https://agilite.slm-lab.net/api/jsonrpc', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@ -26,21 +29,34 @@ export async function GET() {
|
||||
})
|
||||
});
|
||||
|
||||
const responseText = await response.text();
|
||||
console.log('Leantime API Response:', responseText);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch status labels from Leantime');
|
||||
throw new Error(`Leantime API returned ${response.status}: ${responseText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(responseText);
|
||||
} catch (e) {
|
||||
console.error('Failed to parse Leantime response:', e);
|
||||
throw new Error('Invalid JSON response from Leantime');
|
||||
}
|
||||
|
||||
if (!data.result) {
|
||||
console.log('No result in Leantime response');
|
||||
return NextResponse.json({ statusLabels: [] });
|
||||
}
|
||||
|
||||
return NextResponse.json({ statusLabels: data.result });
|
||||
} catch (error) {
|
||||
console.error('Error fetching status labels:', error);
|
||||
console.error('Detailed error in status labels fetch:', error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch status labels" },
|
||||
{
|
||||
error: "Failed to fetch status labels",
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user