1
0
mirror of synced 2025-12-23 11:54:18 -05:00

dedicated search results page (redux) (#29902)

* dedicated search results page (redux)

* Update SearchResults.tsx

* adding pagination

* fix pagination

* say something on NoQuery

* better Flash

* tidying link

* small fixes for results

* debug info

* l18n the meta info

* inDebugMode

* basic jest rendering of the skeleton page

* basic jest rendering test

* fix content tests

* better document title

* fix tests

* quote query in page title

* use home page sidebar

* something when nothing is found

* parseInt no longer needs the 10

* fix linting tests

* fix test

* prettier

* Update pages/search.tsx

Co-authored-by: Rachael Sewell <rachmari@github.com>

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
Co-authored-by: Rachael Sewell <rachmari@github.com>
This commit is contained in:
Peter Bengtsson
2022-08-19 15:36:55 +02:00
committed by GitHub
parent 2206e82584
commit 8765c628ff
25 changed files with 661 additions and 38 deletions

View File

@@ -126,10 +126,20 @@ router.get(
})
)
class ValidationError extends Error {}
const validationMiddleware = (req, res, next) => {
const params = [
{ key: 'query' },
{ key: 'version', default_: 'dotcom', validate: (v) => versionAliases[v] || allVersions[v] },
{
key: 'version',
default_: 'dotcom',
validate: (v) => {
if (versionAliases[v] || allVersions[v]) return true
const valid = [...Object.keys(versionAliases), ...Object.keys(allVersions)]
throw new ValidationError(`'${v}' not in ${valid}`)
},
},
{ key: 'language', default_: 'en', validate: (v) => v in languages },
{
key: 'size',
@@ -160,10 +170,17 @@ const validationMiddleware = (req, res, next) => {
if (cast) {
value = cast(value)
}
if (validate && !validate(value)) {
return res
.status(400)
.json({ error: `Not a valid value (${JSON.stringify(value)}) for key '${key}'` })
try {
if (validate && !validate(value)) {
return res
.status(400)
.json({ error: `Not a valid value (${JSON.stringify(value)}) for key '${key}'` })
}
} catch (err) {
if (err instanceof ValidationError) {
return res.status(400).json({ error: err.toString(), field: key })
}
throw err
}
search[key] = value
}