DIYgod/RSSHub · error · Error
未知的金属类型
Error message
未知的金属类型
What it means
The 长江有色网 price-adjustment route maps the `category` path parameter to a per-metal subdomain through SUB_DOMAIN_MAP (keys: copper, alu, zn, sn, pb, ni). Any value that is not a key yields undefined, and the handler throws a generic Error with the Chinese message '未知的金属类型' ('unknown metal type') before issuing the request. Note the codes are short forms (alu, not aluminium).
Source
Thrown at lib/routes/ccmn/price-adjustment.tsx:91
pb: 'pb.ccmn.cn',
ni: 'ni.ccmn.cn',
};
const READABLE_CATEGORIES = {
copper: '铜',
alu: '铝',
zn: '锌',
sn: '锡',
pb: '铅',
ni: '镍',
};
async function handler(ctx) {
const category = ctx.req.param('category');
const subdomain = SUB_DOMAIN_MAP[category];
if (!subdomain) {
throw new Error('未知的金属类型');
}
const url = `https://${subdomain}`;
const response = await got({
method: 'get',
url,
});
const $ = load(response.data);
const items = $('.content1-text-div')
.toArray()
.map((item) => {
const $item = $(item);
const dataId = $item.attr('data-id');
const $top = $item.find('.top');View on GitHub (pinned to bed535e087)
Solutions
- Use one of the six supported codes: copper, alu, zn, sn, pb, ni.
- Cross-check the value against the route's `parameters.category.options` list declared in the route config.
- For a new metal, confirm ccmn has a dedicated subdomain and add a SUB_DOMAIN_MAP entry.
Example fix
// before // /ccmn/price-adjustment/aluminium // after // /ccmn/price-adjustment/alu
Defensive patterns
Strategy: type-guard
Validate before calling
const KNOWN_METALS = new Set(['copper', 'alu', 'zn', 'sn', 'pb', 'ni']);
function isKnownMetal(category: string): boolean {
return KNOWN_METALS.has(category);
} Type guard
function isKnownMetal(category: string): category is keyof typeof SUB_DOMAIN_MAP {
return Object.prototype.hasOwnProperty.call(SUB_DOMAIN_MAP, category);
} Prevention
- Drive the category from the route's declared `options` list so invalid values never reach the handler.
- Throw InvalidParameterError (not generic Error) so the framework returns a proper 400.
When it happens
Trigger: Requesting `/ccmn/price-adjustment/<x>` where <x> is not one of copper, alu, zn, sn, pb, ni — e.g. `/ccmn/price-adjustment/iron` or `/ccmn/price-adjustment/aluminium`.
Common situations: Supplying the full English name (aluminium, tin, lead, nickel) or the Chinese metal name instead of the documented short code; typos; copy-pasting a path segment from the source site that differs from the route code.
Related errors
- Language parameter is not valid. Please use one of the follo
- Bad timeRange range. See <a href="https://docs.rsshub.app/ro
- This category does not exist. Please refer to the documentat
- Invalid category Id: ${categoryId}
- Invalid sort type: ${sortType}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/ebce61402937d29e.
Report an issue: GitHub.