DIYgod/RSSHub · warning · Error
Unknown type: ${type}
Error message
Unknown type: ${type} What it means
Thrown by the Fantia search route's switch statement when the `type` path parameter does not match any of the four known cases (`fanclubs`, `posts`, `products`, `commissions`). This is a validation gap: the error fires only AFTER the upstream API has already been called (the URL is built with the unvalidated type), so an invalid type wastes a network request before failing. The default case should ideally be unreachable since the parameter defaults to `'posts'`, but a user can override it with any string.
Source
Thrown at lib/routes/fantia/search.ts:212
items = response.data.products.map((item) => ({
title: item.name,
link: `${rootUrl}/products/${item.id}`,
author: item.fanclub.fanclub_name_with_creator_name,
description: `${item.buyable_lowest_plan.description ? `<p>${item.buyable_lowest_plan.description}</p>` : ''}<img src="${item.thumb ? item.thumb.main : item.thumb_micro}">`,
}));
break;
case 'commissions':
items = response.data.commissions.map((item) => ({
title: item.name,
link: `${rootUrl}/commissions/${item.id}`,
author: item.fanclub.fanclub_name_with_creator_name,
description: `${item.buyable_lowest_plan.description ? `<p>${item.buyable_lowest_plan.description}</p>` : ''}<img src="${item.thumb ? item.thumb.main : item.thumb_micro}">`,
}));
break;
default:
throw new Error(`Unknown type: ${type}`);
}
return {
title: `Fantia - Search ${type}`,
link: apiUrl.replace('api/v1/search/', ''),
item: items,
};
}
View on GitHub (pinned to bed535e087)
Solutions
- Use one of the four valid type values: `fanclubs`, `posts`, `products`, or `commissions`.
- Omit the type parameter to default to `posts`.
- Add pre-validation with a Set check before the API call to fail fast and avoid wasting a network request.
Example fix
// before — type is used in the API URL without validation
const type = ctx.req.param('type') || 'posts';
// ... API call happens ...
switch (type) {
// ...
default:
throw new Error(`Unknown type: ${type}`);
}
// after — validate before making the network request
const validTypes = new Set(['fanclubs', 'posts', 'products', 'commissions']);
const type = ctx.req.param('type') || 'posts';
if (!validTypes.has(type)) {
throw new InvalidParameterError(`Unknown type: ${type}. Valid types: ${[...validTypes].join(', ')}`);
} Defensive patterns
Strategy: validation
Validate before calling
const VALID_SEARCH_TYPES = new Set(['fanclubs', 'posts', 'products', 'commissions']);
function validateSearchType(type: string | undefined): string {
const resolved = type ?? 'posts';
if (!VALID_SEARCH_TYPES.has(resolved)) {
throw new InvalidParameterError(`Unknown type: ${type}. Valid: fanclubs, posts, products, commissions`);
}
return resolved;
} Type guard
type SearchType = 'fanclubs' | 'posts' | 'products' | 'commissions';
function isSearchType(value: string): value is SearchType {
return ['fanclubs', 'posts', 'products', 'commissions'].includes(value);
} Prevention
- Validate the type parameter BEFORE constructing the API URL to fail fast.
- Use only the four documented type values.
- Default to 'posts' when the type is omitted.
- Move the Set check above the got() call to avoid wasting a network request on invalid input.
When it happens
Trigger: A user passes an unsupported type value like `/fantia/search/fanclub` (missing 's'), `/fantia/search/article`, or any arbitrary string. The API call to `fantia.jp/api/v1/search/<type>` is made first, and since the response won't have the expected data shape, the switch default case throws.
Common situations: User misspells a type value (e.g., `fanclub` vs `fanclubs`). User passes a type from a different Fantia API version. The route documentation table is consulted but the user misreads the mapping.
Related errors
- Invalid language: ${lang}
- Invalid type: ${type}
- No category '${category}'.
- Unknown bank: ${bank}
- Bad category. See <a href="https://docs.rsshub.app/routes/go
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/df59f2b96b29606e.
Report an issue: GitHub.