Skip to content

Commit

Permalink
bugfix: Catch route not found in spanner (#137)
Browse files Browse the repository at this point in the history
* catch route not found in spanner

* _

* bump package versions
  • Loading branch information
codekeyz authored Nov 29, 2024
1 parent c03ea26 commit 0be851e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/pharaoh/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: pharaoh
description: Minimalist web-server library for Dart
version: 0.0.8+2
version: 0.0.8+3
repository: https://github.com/codekeyz/pharaoh/tree/main/packages/pharaoh

environment:
sdk: ^3.0.0

dependencies:
meta: ^1.15.0
spanner: ^1.0.4
spanner: ^1.0.5
mime: ^1.0.4
collection: ^1.18.0
http_parser: ^4.0.2
Expand Down
17 changes: 17 additions & 0 deletions packages/pharaoh/test/issue_route_not_found_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:pharaoh/pharaoh.dart';
import 'package:spookie/spookie.dart';

void main() {
test('should error on route not found', () async {
final app = Pharaoh()..get('/', (req, res) => res.ok('Hello'));

final tester = await request(app);

await tester.get('/').expectStatus(200).expectBody('Hello').test();

await tester
.get('/come')
.expectStatus(404)
.expectJsonBody({"error": "Route not found: /come"}).test();
});
}
4 changes: 4 additions & 0 deletions packages/spanner/lib/src/tree/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ class Spanner {

wildcardNode = childNode?.wildcardNode ?? wildcardNode;

if (childNode == null && parametricNode == null && wildcardNode == null) {
return RouteResult(resolvedParams, getResults(null));
}

// set root node as current child
rootNode = childNode ?? parametricNode ?? rootNode;

Expand Down
2 changes: 1 addition & 1 deletion packages/spanner/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: spanner
description: Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards.
version: 1.0.4
version: 1.0.5
repository: https://github.com/Pharaoh-Framework/pharaoh/tree/main/packages/spanner

environment:
Expand Down

0 comments on commit 0be851e

Please sign in to comment.