DIYgod/RSSHub · warning · Error
Invalid type: ${type}. Must be one of: ${Object.keys(filterT
Error message
Invalid type: ${type}. Must be one of: ${Object.keys(filterTypeMap).join(', ')} What it means
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.
Source
Thrown at lib/routes/openalex/works.ts:45
field: 'primary_topic.field.id',
domain: 'primary_topic.domain.id',
};
export const handler = async (ctx) => {
const { journals, type, ids } = ctx.req.param();
// Get date 14 days ago (2 weeks)
const twoWeeksAgo = new Date();
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14);
const twoWeeksAgoStr = twoWeeksAgo.toISOString().split('T', 1)[0];
// Build filter parameters
const filters = [`publication_date:>${twoWeeksAgoStr}`, 'has_abstract:true', `primary_location.source.id:${journals}`];
// Add type filter if provided
if (type && ids) {
if (!Object.hasOwn(filterTypeMap, type)) {
throw new Error(`Invalid type: ${type}. Must be one of: ${Object.keys(filterTypeMap).join(', ')}`);
}
const typeField = filterTypeMap[type];
filters.push(`${typeField}:${ids}`);
}
const filter = filters.join(',');
const apiUrl = `${rootUrl}/works`;
const response = await ofetch(apiUrl, {
query: {
filter,
sort: 'publication_date:desc',
'per-page': 100,
},
});
const seenTitleKeys = new Set<string>();
View on GitHub (pinned to bed535e087)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Validate type against filterTypeMap keys before use
const validTypes = Object.keys(filterTypeMap);
if (type && !validTypes.includes(type)) {
throw new Error(
`Invalid type: ${type}. Must be one of: ${validTypes.join(', ')}`
);
} Type guard
function isValidFilterType(type: string): type is keyof typeof filterTypeMap {
return Object.hasOwn(filterTypeMap, type);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${tagResponse.msg}
- Invalid tagId
- response.error.message
- No articles found for this channel. Please make sure the cha
- No posts found for this channel. Please make sure the channe
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/6e3048940c21aee1.
Report an issue: GitHub.