Skip to content

Commit 0be851e

Browse files
authored
bugfix: Catch route not found in spanner (#137)
* catch route not found in spanner * _ * bump package versions
1 parent c03ea26 commit 0be851e

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

packages/pharaoh/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: pharaoh
22
description: Minimalist web-server library for Dart
3-
version: 0.0.8+2
3+
version: 0.0.8+3
44
repository: https://github.com/codekeyz/pharaoh/tree/main/packages/pharaoh
55

66
environment:
77
sdk: ^3.0.0
88

99
dependencies:
1010
meta: ^1.15.0
11-
spanner: ^1.0.4
11+
spanner: ^1.0.5
1212
mime: ^1.0.4
1313
collection: ^1.18.0
1414
http_parser: ^4.0.2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:pharaoh/pharaoh.dart';
2+
import 'package:spookie/spookie.dart';
3+
4+
void main() {
5+
test('should error on route not found', () async {
6+
final app = Pharaoh()..get('/', (req, res) => res.ok('Hello'));
7+
8+
final tester = await request(app);
9+
10+
await tester.get('/').expectStatus(200).expectBody('Hello').test();
11+
12+
await tester
13+
.get('/come')
14+
.expectStatus(404)
15+
.expectJsonBody({"error": "Route not found: /come"}).test();
16+
});
17+
}

packages/spanner/lib/src/tree/tree.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ class Spanner {
202202

203203
wildcardNode = childNode?.wildcardNode ?? wildcardNode;
204204

205+
if (childNode == null && parametricNode == null && wildcardNode == null) {
206+
return RouteResult(resolvedParams, getResults(null));
207+
}
208+
205209
// set root node as current child
206210
rootNode = childNode ?? parametricNode ?? rootNode;
207211

packages/spanner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: spanner
22
description: Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards.
3-
version: 1.0.4
3+
version: 1.0.5
44
repository: https://github.com/Pharaoh-Framework/pharaoh/tree/main/packages/spanner
55

66
environment:

0 commit comments

Comments
 (0)