From ede3618b1db1649c3dcbaeb3a74a798b363db212 Mon Sep 17 00:00:00 2001 From: Ray Papworth Date: Mon, 20 Jan 2025 16:02:10 +0000 Subject: [PATCH] add the url to the invalid api message --- api/ApiRouter.inc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/api/ApiRouter.inc b/api/ApiRouter.inc index 8cdc3c1f5..9ee66843c 100644 --- a/api/ApiRouter.inc +++ b/api/ApiRouter.inc @@ -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;