2025-05-29 07:32:13 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
|
const xTagHeader = getRequestHeader(event, "x-tag");
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Request received with x-tag:', xTagHeader);
|
2025-05-29 07:32:13 +02:00
|
|
|
|
2025-06-09 23:33:20 +02:00
|
|
|
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
|
|
|
|
console.error('[get-interest-by-id] Authentication failed - invalid x-tag:', xTagHeader);
|
2025-05-29 07:32:13 +02:00
|
|
|
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const query = getQuery(event);
|
|
|
|
|
const { id } = query;
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Request for ID:', id);
|
2025-05-29 07:32:13 +02:00
|
|
|
|
|
|
|
|
if (!id) {
|
2025-06-09 23:33:20 +02:00
|
|
|
console.error('[get-interest-by-id] Missing ID in request');
|
2025-05-29 07:32:13 +02:00
|
|
|
throw createError({ statusCode: 400, statusMessage: "ID is required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Fetching interest:', id);
|
2025-05-29 07:32:13 +02:00
|
|
|
const interest = await getInterestById(id as string);
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Successfully fetched interest:', id);
|
2025-05-29 07:32:13 +02:00
|
|
|
return interest;
|
2025-06-09 23:33:20 +02:00
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('[get-interest-by-id] Error occurred:', error);
|
|
|
|
|
console.error('[get-interest-by-id] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
|
|
|
|
|
|
|
|
|
// Check if it's a 404 error
|
|
|
|
|
if (error.statusCode === 404 || error.status === 404) {
|
|
|
|
|
console.error('[get-interest-by-id] Interest not found with ID:', id);
|
|
|
|
|
throw createError({
|
|
|
|
|
statusCode: 404,
|
|
|
|
|
statusMessage: `Interest not found with ID: ${id}. It may have been deleted or not yet synchronized.`
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-29 07:32:13 +02:00
|
|
|
if (error instanceof Error) {
|
|
|
|
|
throw createError({ statusCode: 500, statusMessage: error.message });
|
|
|
|
|
} else {
|
|
|
|
|
throw createError({
|
|
|
|
|
statusCode: 500,
|
|
|
|
|
statusMessage: "An unexpected error occurred",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|