fix: safely handle empty/null models array in getVideoBySlug
- Added null/undefined checks before mapping models array - Filter out invalid entries in models junction table data - Default to empty array if models is not an array - Prevents "Cannot read properties of undefined" errors on video pages This fix ensures the video detail page works even when model associations are missing or malformed in the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -266,7 +266,14 @@ export async function getVideoBySlug(
|
||||
if (videos.length === 0) {
|
||||
throw new Error("Video not found");
|
||||
}
|
||||
videos[0].models = videos[0].models.map((u) => u.directus_users_id!);
|
||||
// Handle models array - filter out null/undefined and map to user objects
|
||||
if (Array.isArray(videos[0].models)) {
|
||||
videos[0].models = videos[0].models
|
||||
.filter((u) => u && u.directus_users_id)
|
||||
.map((u) => u.directus_users_id!);
|
||||
} else {
|
||||
videos[0].models = [];
|
||||
}
|
||||
|
||||
return videos[0];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user