Skip to content

Commit

Permalink
add the url to the invalid api message
Browse files Browse the repository at this point in the history
  • Loading branch information
70ray committed Jan 20, 2025
1 parent e2919d8 commit ede3618
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions api/ApiRouter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ class ApiRouter
$node = $this->root;
$data = [];
$parts = explode("/", $url);
foreach ($parts as $part) {
$next_node = $node->children[$part] ?? null;
if ($next_node) {
$node = $next_node;
} else {
[$param_name, $validator] = $this->get_validator($node);
$node = $node->children[$param_name];
$data[$param_name] = $validator($part, $data);
try {
foreach ($parts as $part) {
$next_node = $node->children[$part] ?? null;
if ($next_node) {
$node = $next_node;
} else {
[$param_name, $validator] = $this->get_validator($node);
$node = $node->children[$param_name];
$data[$param_name] = $validator($part, $data);
}
}
}
if (empty($node->handlers)) {
throw new InvalidAPI();
if (empty($node->handlers)) {
throw new InvalidAPI();
}
} catch (InvalidAPI $exception) {
throw new InvalidAPI($exception->getMessage() . ": $url");
}
$method = $_SERVER["REQUEST_METHOD"];
$handler = $node->handlers[$method] ?? null;
Expand Down

0 comments on commit ede3618

Please sign in to comment.