| 2 | import { getDataByLanguage } from '../../lib/get-data.js' |
| 3 | |
| 4 | function getProductExampleData(product, key, language) { |
| 5 | // Because getDataByLanguage() depends on reading data files from |
| 6 | // disk, asking for something that doesn't exist would throw a |
| 7 | // `ENOENT` error from `fs.readFile` but we want that to default |
| 8 | // to `undefined` because certain product's don't have all product |
| 9 | // examples. |
| 10 | try { |
| 11 | return getDataByLanguage(`product-examples.${product}.${key}`, language) |
| 12 | } catch (error) { |
| 13 | if (error.code === 'ENOENT') return |
| 14 | throw error |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | export default async function productExamples(req, res, next) { |
| 19 | if (!req.context.page) return next() |