зеркало из https://github.com/github/docs.git
render a slim 404 message on /api/* (#31818)
This commit is contained in:
Родитель
b1610289b2
Коммит
bf870f2960
|
@ -37,4 +37,8 @@ if (process.env.ELASTICSEARCH_URL) {
|
|||
)
|
||||
}
|
||||
|
||||
router.get('*', (req, res, next) => {
|
||||
res.status(404).json({ error: `${req.path} not found` })
|
||||
})
|
||||
|
||||
export default router
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import { expect, jest, test } from '@jest/globals'
|
||||
|
||||
import { get } from '../helpers/e2etest.js'
|
||||
|
||||
describe('general /api pages', () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
|
||||
test("any /api URL that isn't found should JSON", async () => {
|
||||
const res = await get('/api')
|
||||
expect(res.statusCode).toBe(404)
|
||||
expect(res.headers['content-type']).toMatch(/application\/json/)
|
||||
})
|
||||
|
||||
test("any /api/* URL that isn't found should be JSON", async () => {
|
||||
const res = await get('/api/yadayada')
|
||||
expect(res.statusCode).toBe(404)
|
||||
expect(JSON.parse(res.text).error).toBe('/yadayada not found')
|
||||
})
|
||||
})
|
Загрузка…
Ссылка в новой задаче