missions api2 gitea

This commit is contained in:
alma 2025-05-06 20:33:07 +02:00
parent 60b2555e3e
commit 3e803e3112

View File

@ -658,6 +658,8 @@ export class LeantimeService {
*/
async deleteProject(projectId: number): Promise<boolean> {
try {
console.log(`Attempting to delete Leantime project ${projectId} with method: leantime.rpc.Projects.Projects.deleteProject`);
const response = await axios.post(
this.getApiEndpoint(),
{
@ -676,7 +678,49 @@ export class LeantimeService {
}
);
return response.data && response.data.result === true;
// Log the full response for debugging
console.log(`Leantime delete response for project ${projectId}:`, JSON.stringify(response.data, null, 2));
if (!response.data || response.data.result !== true) {
console.error(`Failed to delete Leantime project ${projectId} with first method. API Response:`, JSON.stringify(response.data, null, 2));
// Try alternative method (without double "Projects")
console.log(`Trying alternative method: leantime.rpc.Projects.deleteProject for project ${projectId}`);
const alternativeResponse = await axios.post(
this.getApiEndpoint(),
{
method: 'leantime.rpc.Projects.deleteProject',
jsonrpc: '2.0',
id: 1,
params: {
id: projectId
}
},
{
headers: {
'Content-Type': 'application/json',
'X-API-Key': this.apiToken
}
}
);
// Log the alternative response
console.log(`Alternative method response for project ${projectId}:`, JSON.stringify(alternativeResponse.data, null, 2));
// Check if alternative method worked
if (alternativeResponse.data && alternativeResponse.data.result === true) {
console.log(`Successfully deleted project ${projectId} with alternative method`);
return true;
}
// If we get here, both methods failed
console.error(`Failed to delete Leantime project ${projectId} with both methods.`);
return false;
}
console.log(`Successfully deleted Leantime project ${projectId}`);
return true;
} catch (error) {
// Check if this is a rate limiting error
if (axios.isAxiosError(error) && error.response?.status === 429) {
@ -687,6 +731,7 @@ export class LeantimeService {
try {
// Retry the delete
console.log(`Retrying deletion after rate limit for project ${projectId}`);
const retryResponse = await axios.post(
this.getApiEndpoint(),
{
@ -705,14 +750,38 @@ export class LeantimeService {
}
);
return retryResponse.data && retryResponse.data.result === true;
// Log the retry response
console.log(`Retry response for project ${projectId}:`, JSON.stringify(retryResponse.data, null, 2));
if (retryResponse.data && retryResponse.data.result === true) {
console.log(`Successfully deleted project ${projectId} on retry`);
return true;
} else {
console.error(`Retry failed to delete project ${projectId}. Response:`, JSON.stringify(retryResponse.data, null, 2));
return false;
}
} catch (retryError) {
console.error(`Error on retry delete for project ${projectId}:`, retryError);
if (axios.isAxiosError(retryError)) {
console.error('Retry error details:', {
status: retryError.response?.status,
data: retryError.response?.data,
message: retryError.message
});
}
return false;
}
}
// Log detailed error information
console.error(`Error deleting Leantime project ${projectId}:`, error);
if (axios.isAxiosError(error)) {
console.error('Error details:', {
status: error.response?.status,
data: error.response?.data,
message: error.message
});
}
return false;
}
}