| 300 | // which is slightly different depending on the "sub-version" (e.g. /legacy) |
| 301 | // This function is a single place to take care of all of these error handlings |
| 302 | async function handleGetSearchResultsError(req, res, error, options) { |
| 303 | if (process.env.NODE_ENV === 'development') { |
| 304 | console.error(`Error calling getSearchResults(${options})`, error) |
| 305 | } else { |
| 306 | const reports = FailBot.report(error, Object.assign({ url: req.url }, options)) |
| 307 | // It might be `undefined` if no backends are configured which |
| 308 | // is likely when using production NODE_ENV on your laptop |
| 309 | // where you might not have a HATSTACK_URL configured. |
| 310 | if (reports) await Promise.all(reports) |
| 311 | } |
| 312 | res.status(500).json({ error: error.message }) |
| 313 | } |
| 314 | |
| 315 | // Alias for the latest version |
| 316 | router.get('/', (req, res) => { |