return not found response for missing requests
[sc2-widget] / widget.php
index eec063774ea0932f227c4d48f5f02f935a82a49d..736a7b1305b04eb8ee3f11bc4a409d44c572ca3f 100644 (file)
@@ -18,13 +18,17 @@ function error($message, $status = 500)
 }
 
 $request = trim($_SERVER['PATH_INFO'], '/');
-if (!file_exists("$request.json")) {
+$target = "$request.json";
+if (!file_exists($target)) {
        if (!is_numeric($request)) {
                error("Unknown profile request <q>$request</q>", 400);
        }
-       system("./getsc2clan $request | sponge $request.json", $exitcode);
+       system("./getsc2clan $request | sponge $target", $exitcode);
        if ($exitcode) {
                error("No results for profile id $request from Blizzard", 503);
        }
 }
+if (!filesize($target)) {
+       error("No clan data for <q>$request</q>", 404);
+}
 require('widget.html');