{"record":{"id":"6e3048940c21aee1","repo":"DIYgod/RSSHub","slug":"invalid-type-type-must-be-one-of-object-ke","errorCode":null,"errorMessage":"Invalid type: ${type}. Must be one of: ${Object.keys(filterTypeMap).join(', ')}","messagePattern":"Invalid type: (.+?)\\. Must be one of: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/openalex/works.ts","lineNumber":45,"sourceCode":"    field: 'primary_topic.field.id',\n    domain: 'primary_topic.domain.id',\n};\n\nexport const handler = async (ctx) => {\n    const { journals, type, ids } = ctx.req.param();\n\n    // Get date 14 days ago (2 weeks)\n    const twoWeeksAgo = new Date();\n    twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14);\n    const twoWeeksAgoStr = twoWeeksAgo.toISOString().split('T', 1)[0];\n\n    // Build filter parameters\n    const filters = [`publication_date:>${twoWeeksAgoStr}`, 'has_abstract:true', `primary_location.source.id:${journals}`];\n\n    // Add type filter if provided\n    if (type && ids) {\n        if (!Object.hasOwn(filterTypeMap, type)) {\n            throw new Error(`Invalid type: ${type}. Must be one of: ${Object.keys(filterTypeMap).join(', ')}`);\n        }\n        const typeField = filterTypeMap[type];\n        filters.push(`${typeField}:${ids}`);\n    }\n\n    const filter = filters.join(',');\n\n    const apiUrl = `${rootUrl}/works`;\n    const response = await ofetch(apiUrl, {\n        query: {\n            filter,\n            sort: 'publication_date:desc',\n            'per-page': 100,\n        },\n    });\n\n    const seenTitleKeys = new Set<string>();\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/openalex/works.ts#L27-L63","documentation":"Thrown when the `type` path parameter for the OpenAlex works route is provided but does not match any key in the `filterTypeMap` object. Valid types are: `subfield`, `topic`, `field`, `domain`. These map to OpenAlex API filter field names like `primary_topic.subfield.id`, `primary_topic.id`, etc. The error is only thrown when both `type` and `ids` are non-empty.","triggerScenarios":"Requesting `/openalex/<journals>/<type>/<ids>` with a type value not among subfield/topic/field/domain (e.g., 'journal', 'author', 'keyword'). The check only fires when both `type` and `ids` params are present; if only `journals` is provided, no type validation occurs.","commonSituations":"User passes a filter type name from the OpenAlex API that isn't in the curated map (e.g., 'institution', 'concept'). Typo in the type parameter. User expects a broader set of filter types than the four supported.","solutions":["Use only one of: subfield, topic, field, domain as the type parameter.","If you need a different filter type, add it to `filterTypeMap` in `lib/routes/openalex/works.ts` with the corresponding OpenAlex field name.","Omit both `type` and `ids` to get works without topic filtering."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate type against filterTypeMap keys before use\nconst validTypes = Object.keys(filterTypeMap);\nif (type && !validTypes.includes(type)) {\n    throw new Error(\n        `Invalid type: ${type}. Must be one of: ${validTypes.join(', ')}`\n    );\n}","typeGuard":"function isValidFilterType(type: string): type is keyof typeof filterTypeMap {\n    return Object.hasOwn(filterTypeMap, type);\n}","tryCatchPattern":null,"preventionTips":["Use only subfield, topic, field, or domain as the type parameter.","Omit both type and ids to skip topic filtering.","Check filterTypeMap keys for the current supported set."],"tags":["validation","openalex","api","research"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}