Skip to content

Commit 85b1e04

Browse files
committed
use InertiaPageNotFoundError
1 parent 041d1b8 commit 85b1e04

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

packages/vite/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export { supercharge }
77
export { HotReloadFile } from './plugin/hotfile.js'
88
export { PluginConfigContract, DevServerUrl } from './plugin/types.js'
99

10-
export { resolvePageComponent } from './inertia-helpers.js'
10+
export { resolvePageComponent, InertiaPageNotFoundError } from './inertia-helpers.js'
1111
export { Vite, ViteTagAttributes } from './backend/vite.js'
1212
export { ViteConfig } from './backend/vite-config.js'
1313
export { ViteServiceProvider } from './vite-service-provider.js'

packages/vite/src/inertia-helpers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11

2+
export class InertiaPageNotFoundError extends Error {
3+
/**
4+
* Create a new instance.
5+
*/
6+
constructor (path: string) {
7+
super(`Inertia page not found: ${path}`)
8+
9+
this.name = 'PageNotFoundError'
10+
InertiaPageNotFoundError.captureStackTrace(this, this.constructor)
11+
}
12+
}
13+
214
/**
315
* Resolves the inertia page component for the given `path` from the available `pages`.
416
*
@@ -16,7 +28,7 @@ export async function resolvePageComponent<T> (path: string, pages: Record<strin
1628
const page = pages[path]
1729

1830
if (page == null) {
19-
throw new Error(`Inertia page not found: ${path}`)
31+
throw new InertiaPageNotFoundError(path)
2032
}
2133

2234
return typeof page === 'function'

packages/vite/test/inertia-helpers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import { test } from 'uvu'
33
import { expect } from 'expect'
4-
import { resolvePageComponent } from '../dist/index.js'
4+
import { resolvePageComponent, InertiaPageNotFoundError } from '../dist/index.js'
55

66
const testPage = './fixtures/test-page.js'
77

@@ -16,6 +16,10 @@ test('pass eagerly globed value to resolvePageComponent', async () => {
1616
})
1717

1818
test('fails for non-existing page', async () => {
19+
await expect(
20+
resolvePageComponent('./fixtures/not-existing.js', import.meta.glob('./fixtures/*.js'))
21+
).rejects.toThrowError(InertiaPageNotFoundError)
22+
1923
await expect(
2024
resolvePageComponent('./fixtures/not-existing.js', import.meta.glob('./fixtures/*.js'))
2125
).rejects.toThrow('Inertia page not found: ./fixtures/not-existing.js')

0 commit comments

Comments
 (0)