@@ -25,23 +25,40 @@ export const getModrinthMeta = async (req, res, next) => {
2525
2626 let name = id ;
2727 let url = null ;
28+ let data = null ;
2829
2930 if ( type === "user" ) {
3031 const user = await modrinthClient . getUser ( id ) ;
32+ data = user ;
33+ if ( ! data ) {
34+ return res . status ( 404 ) . json ( { error : "User not found" } ) ;
35+ }
3136 name = user . username ;
3237 url = `https://modrinth.com/user/${ id } ` ;
3338 } else if ( type === "project" ) {
3439 const project = await modrinthClient . getProjectV3 ( id ) ;
40+ data = project ;
41+ if ( ! data ) {
42+ return res . status ( 404 ) . json ( { error : "Project not found" } ) ;
43+ }
3544 name = project . name || project . title ;
3645 const projectType = project . project_types ?. [ 0 ] || project . project_type ;
3746 const urlSegment = PROJECT_TYPE_URL_SEGMENT [ projectType ] || projectType ;
3847 url = `https://modrinth.com/${ urlSegment } /${ id } ` ;
3948 } else if ( type === "organization" ) {
4049 const org = await modrinthClient . getOrganization ( id ) ;
50+ data = org ;
51+ if ( ! data ) {
52+ return res . status ( 404 ) . json ( { error : "Organization not found" } ) ;
53+ }
4154 name = org . name ;
4255 url = `https://modrinth.com/organization/${ id } ` ;
4356 } else if ( type === "collection" ) {
4457 const collection = await modrinthClient . getCollection ( id ) ;
58+ data = collection ;
59+ if ( ! data ) {
60+ return res . status ( 404 ) . json ( { error : "Collection not found" } ) ;
61+ }
4562 name = collection . name ;
4663 url = `https://modrinth.com/collection/${ id } ` ;
4764 }
@@ -52,7 +69,12 @@ export const getModrinthMeta = async (req, res, next) => {
5269 res . setHeader ( "Cache-Control" , `public, max-age=${ API_CACHE_TTL } ` ) ;
5370 res . json ( result ) ;
5471 } catch ( err ) {
55- logger . warn ( `Error fetching modrinth meta for "${ req . params . type } " "${ req . params . id } ": ${ err . message } ` ) ;
72+ logger . warn ( {
73+ err,
74+ platform : PLATFORM . MODRINTH ,
75+ entity : req . params . type ,
76+ identifier : req . params . id
77+ } , "Error fetching meta" ) ;
5678 next ( err ) ;
5779 }
5880} ;
0 commit comments