]> jfr.im git - uguu.git/blobdiff - src/Classes/Response.php
Update config.json
[uguu.git] / src / Classes / Response.php
index 6e60b69965430fcf1e4446968a92bc206acb9726..18c743d04a52d1009be3f62fe2ae359086337de2 100644 (file)
@@ -2,7 +2,7 @@
     /**
      * Uguu
      *
-     * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
@@ -27,7 +27,8 @@
         /**
          * Takes a string as an argument and sets the header to the appropriate content type
          *
-         * @param $response_type string The type of response you want to return. Valid options are: csv, html, json, text.
+         * @param $response_type string The type of response you want to return.
+         *                       Valid options are: csv, html, json, text.
          */
         public function __construct(string $response_type)
         {
@@ -55,7 +56,6 @@
                 default:
                     header('Content-Type: application/json; charset=UTF-8');
                     $this->type = 'json';
-                    $this->error(400, 'Invalid response type. Valid options are: csv, html, json, text.');
                     break;
             }
         }
@@ -66,7 +66,7 @@
          * @param $code mixed The HTTP status code to return.
          * @param $desc string The description of the error.
          */
-        public function error(mixed $code, string $desc):void
+        public function error(int $code, string $desc):string
         {
             $response = match ($this->type) {
                 'csv' => $this->csvError($desc),
@@ -76,6 +76,7 @@
             };
             http_response_code($code);
             echo $response;
+            exit(1);
         }
         
         /* Returning a string that contains the error message. */
         }
         
         /**
-         * "If the type is csv, then call the csvSuccess function, if the type is html, then call the htmlSuccess function, etc."
+         * "If the type is csv, then call the csvSuccess function,
+         * if the type is html, then call the htmlSuccess function, etc."
          *
          * The `match` keyword is a new feature in PHP 8. It's a lot like a switch statement, but it's more powerful
          *
             }
             return $result;
         }
-    }
+    }
\ No newline at end of file