Skip to content

Commit d27720c

Browse files
author
Peter Bengtsson
authored
404 if apiVersion is unrecognized (#33850)
1 parent 5da624a commit d27720c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pages/[versionId]/rest/overview/endpoints-available-for-github-apps.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
9494
const automatedPageContext = getAutomatedPageContextFromRequest(req)
9595
const enabledForApps = await getEnabledForApps(currentVersion, apiVersion)
9696

97+
// If getEnabledForApps came back as undefined, it means that nothing
98+
// could be found for that `apiVersion`
99+
if (!enabledForApps) {
100+
return {
101+
notFound: true,
102+
}
103+
}
104+
97105
return {
98106
props: {
99107
mainContext,

tests/rendering/rest.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { jest, test } from '@jest/globals'
22
import { slug } from 'github-slugger'
33

4-
import { getDOM } from '../helpers/e2etest.js'
4+
import { get, getDOM } from '../helpers/e2etest.js'
55
import getRest, { getEnabledForApps, categoriesWithoutSubcategories } from '../../lib/rest/index.js'
66
import { isApiVersioned, allVersions } from '../../lib/all-versions.js'
77
import { getDiffOpenAPIContentRest } from '../../script/rest/test-open-api-schema.js'
@@ -61,6 +61,15 @@ describe('REST references docs', () => {
6161
}
6262
})
6363

64+
test('404 if unrecognized apiVersion', async () => {
65+
const res = await get(
66+
`/en/rest/overview/endpoints-available-for-github-apps?${new URLSearchParams({
67+
apiVersion: 'junk',
68+
})}`
69+
)
70+
expect(res.statusCode).toBe(404)
71+
})
72+
6473
test('test the latest version of the OpenAPI schema categories/subcategories to see if it matches the content/rest directory', async () => {
6574
const differences = await getDiffOpenAPIContentRest()
6675
const errorMessage = formatErrors(differences)

0 commit comments

Comments
 (0)