ParamParser,
} from './route-resolver/matchers/matcher-pattern'
+export { miss, MatchMiss } from './route-resolver/matchers/errors'
+
// in the new experimental router, there are only parents
// this should create type errors if someone is realying on children
declare module 'vue-router' {
/**
- * NOTE: for these classes to keep the same code we need to tell TS with `"useDefineForClassFields": true` in the `tsconfig.json`
- */
-
-// TODO: document helpers if kept. The helpers could also be moved to the generated code to reduce bundle size. After all, user is unlikely to write these manually
-
-/**
- * Error throw when a matcher miss
+ * Error throw when a matcher matches by regex but validation fails.
*/
export class MatchMiss extends Error {
name = 'MatchMiss'
}
-// NOTE: not sure about having a helper. Using `new MatchMiss(description?)` is good enough
-export const miss = () => new MatchMiss()
-// TODO: which one?, the return type of never makes types work anyway
-// export const throwMiss = () => { throw new MatchMiss() }
-// export const throwMiss = (...args: ConstructorParameters<typeof MatchMiss>) => { throw new MatchMiss(...args) }
-
/**
- * Error throw when a param is invalid when parsing params from path, query, or hash.
+ * Helper to create a {@link MatchMiss} error.
+ * @param args - Arguments to pass to the `MatchMiss` constructor.
+ *
+ * @example
+ * ```ts
+ * throw miss()
+ * // in a number param matcher
+ * throw miss('Number must be finite')
+ * ```
*/
-export class ParamInvalid extends Error {
- name = 'ParamInvalid'
- constructor(public param: string) {
- super()
- }
-}
-export const invalid = (param: string) => new ParamInvalid(param)
+export const miss = (...args: ConstructorParameters<typeof MatchMiss>) =>
+ new MatchMiss(...args)
MatcherPatternHash,
} from './matcher-pattern'
import { NEW_MatcherRecord } from '../old/resolver-dynamic'
-import { invalid, miss } from './errors'
+import { miss } from './errors'
export const ANY_PATH_PATTERN_MATCHER: MatcherPatternPath<{
pathMatch: string
}
const id = Number(match[1])
if (Number.isNaN(id)) {
- throw invalid('id')
- // throw miss()
+ throw miss(`Invalid number: ${String(match[1])}`)
}
return { id }
},