mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[APM] Improve error message for route matching (#126455)
This commit is contained in:
parent
e0e14c4b47
commit
c8a206545a
2 changed files with 19 additions and 3 deletions
|
@ -196,7 +196,15 @@ describe('createRouter', () => {
|
|||
it('throws an error if the given path does not match any routes', () => {
|
||||
expect(() => {
|
||||
router.getParams('/service-map', history.location);
|
||||
}).toThrowError('No matching route found for /service-map');
|
||||
}).toThrowError('/service-map does not match current path /');
|
||||
|
||||
expect(() => {
|
||||
router.getParams('/services/{serviceName}', history.location);
|
||||
}).toThrowError('/services/{serviceName} does not match current path /');
|
||||
|
||||
expect(() => {
|
||||
router.getParams('/service-map', '/services/{serviceName}', history.location);
|
||||
}).toThrowError('None of /service-map, /services/{serviceName} match current path /');
|
||||
});
|
||||
|
||||
it('does not throw an error if the given path does not match any routes but is marked as optional', () => {
|
||||
|
@ -248,7 +256,7 @@ describe('createRouter', () => {
|
|||
|
||||
expect(() => {
|
||||
router.matchRoutes('/traces', history.location);
|
||||
}).toThrowError('No matching route found for /traces');
|
||||
}).toThrowError('/traces does not match current path /service-map');
|
||||
});
|
||||
|
||||
it('applies defaults', () => {
|
||||
|
|
|
@ -99,7 +99,15 @@ export function createRouter<TRoutes extends RouteMap>(routes: TRoutes): Router<
|
|||
if (optional) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(`No matching route found for ${paths}`);
|
||||
|
||||
let errorMessage: string;
|
||||
|
||||
if (paths.length === 1) {
|
||||
errorMessage = `${paths[0]} does not match current path ${location.pathname}`;
|
||||
} else {
|
||||
errorMessage = `None of ${paths.join(', ')} match current path ${location.pathname}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return matches.slice(0, matchIndex + 1).map((matchedRoute) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue