Skip to content

Commit 31a4441

Browse files
committed
refactor: remove redundant custom exceptions
1 parent 0dac61f commit 31a4441

File tree

9 files changed

+12
-94
lines changed

9 files changed

+12
-94
lines changed

index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@ export { HttpContext } from './src/http_context/main.js'
2121
export { HttpException } from './src/exceptions/http_exception.js'
2222
export { AbortException } from './src/exceptions/abort_exception.js'
2323
export { RouteNotFoundException } from './src/exceptions/route_not_found.js'
24-
export { CannotMakeURLException } from './src/exceptions/cannot_make_url.js'
25-
export { DuplicateRouteException } from './src/exceptions/duplicate_route.js'
2624
export { CannotLookupRouteException } from './src/exceptions/cannot_lookup_route.js'
27-
export { DuplicateRouteNameException } from './src/exceptions/duplicate_route_name.js'
28-
export { DuplicateRouteParamException } from './src/exceptions/duplicate_route_param.js'

src/exceptions/cannot_make_url.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/exceptions/duplicate_route.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/exceptions/duplicate_route_name.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/exceptions/duplicate_route_param.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/router/lookup_store/url_builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import { stringify } from 'qs'
1111
import encodeUrl from 'encodeurl'
12+
import { RuntimeException } from '@poppinss/utils'
1213
import type Encryption from '@adonisjs/encryption'
1314
import type { RouteFinder } from './route_finder.js'
14-
import { CannotMakeURLException } from '../../exceptions/cannot_make_url.js'
1515

1616
/**
1717
* URL builder class is used to create URIs for pre-registered
@@ -69,7 +69,7 @@ export class UrlBuilder {
6969
*/
7070
#ensureHasWildCardValues(pattern: string, values?: string[]) {
7171
if (!values || !Array.isArray(values) || !values.length) {
72-
throw new CannotMakeURLException(
72+
throw new RuntimeException(
7373
`Cannot make URL for "${pattern}" route. Invalid value provided for wildcard param`
7474
)
7575
}
@@ -80,7 +80,7 @@ export class UrlBuilder {
8080
*/
8181
#ensureHasParamValue(pattern: string, param: string, value: string) {
8282
if (value === undefined || value === null) {
83-
throw new CannotMakeURLException(
83+
throw new RuntimeException(
8484
`Cannot make URL for "${pattern}" route. Missing value for "${param}" param`
8585
)
8686
}

src/router/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
*/
99

1010
import is from '@sindresorhus/is'
11+
import type Encryption from '@adonisjs/encryption'
12+
import { RuntimeException } from '@poppinss/utils'
13+
import type { Application } from '@adonisjs/application'
14+
1115
import { Route } from './route.js'
1216
import { RouteGroup } from './group.js'
1317
import { BriskRoute } from './brisk.js'
@@ -16,10 +20,6 @@ import { toRoutesJSON } from '../helpers.js'
1620
import { RouteResource } from './resource.js'
1721
import { LookupStore } from './lookup_store/main.js'
1822
import { RouteMatchers as Matchers } from './matchers.js'
19-
import { DuplicateRouteNameException } from '../exceptions/duplicate_route_name.js'
20-
21-
import type Encryption from '@adonisjs/encryption'
22-
import type { Application } from '@adonisjs/application'
2323

2424
import type { LazyImport } from '../types/base.js'
2525
import { MiddlewareStore } from '../middleware/store.js'
@@ -300,7 +300,7 @@ export class Router<
300300
* to ensure that only one route is returned during lookup.
301301
*/
302302
if (route.name && routeNames.has(route.name)) {
303-
throw new DuplicateRouteNameException(
303+
throw new RuntimeException(
304304
`Route with duplicate name found. A route with name "${route.name}" already exists`
305305
)
306306
}

src/router/store.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
// @ts-expect-error
1111
import matchit from '@poppinss/matchit'
1212
import lodash from '@poppinss/utils/lodash'
13-
import { DuplicateRouteException } from '../exceptions/duplicate_route.js'
14-
import { DuplicateRouteParamException } from '../exceptions/duplicate_route_param.js'
13+
import { RuntimeException } from '@poppinss/utils'
1514
import type {
1615
RouteJSON,
1716
MatchedRoute,
@@ -88,9 +87,7 @@ export class RoutesStore {
8887
for (let token of tokens) {
8988
if ([1, 3].includes(token.type)) {
9089
if (collectedParams.has(token.val)) {
91-
throw new DuplicateRouteParamException(
92-
`Duplicate param "${token.val}" found in "${route.pattern}"`
93-
)
90+
throw new RuntimeException(`Duplicate param "${token.val}" found in "${route.pattern}"`)
9491
} else {
9592
collectedParams.add(token.val)
9693
}
@@ -118,7 +115,7 @@ export class RoutesStore {
118115
* Check for duplicate route for the same domain and method
119116
*/
120117
if (methodRoutes.routes[route.pattern]) {
121-
throw new DuplicateRouteException(
118+
throw new RuntimeException(
122119
`Duplicate route found. "${method}: ${route.pattern}" route already exists`
123120
)
124121
}

src/server/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import { HttpContext } from '../http_context/main.js'
2929
import { MiddlewareStore } from '../middleware/store.js'
3030
import { finalHandler } from './factories/final_handler.js'
3131
import { writeResponse } from './factories/write_response.js'
32-
import { middlewareHandler } from './factories/middleware_handler.js'
3332
import { asyncLocalStorage } from '../http_context/local_storage.js'
33+
import { middlewareHandler } from './factories/middleware_handler.js'
3434

3535
/**
3636
* The HTTP server implementation to handle incoming requests and respond using the

0 commit comments

Comments
 (0)