Summary
The code works but lacks error handling and type safety, impacting maintainability and robustness.

CodeCritic AI
Premium AI code review workspace
Code Quality Score
75/100
Summary
The code works but lacks error handling and type safety, impacting maintainability and robustness.
Issues Found
Line 2-3
The code does not handle potential errors from the fetch call or the JSON parsing, which could lead to unhandled promise rejections.
Line 6
The 'any' type in the map function removes type safety, making the code more prone to errors and harder to maintain.
Line 2
String concatenation for the fetch URL can lead to mistakes and is harder to read.
Improved Code
export async function getUserProfile(userId: string) {
try {
const response = await fetch(`/api/users/${userId}`);
const user = await response.json();
if (user.isAdmin) {
console.log("admin user");
}
return {
name: user.name,
projects: user.projects.map((project: Project) => project.title),
};
} catch (error) {
console.error('Failed to fetch user profile:', error);
throw error;
}
}
interface Project {
title: string;
}