Better Errors

This commit is contained in:
2024-07-23 01:12:05 +02:00
parent 30849019af
commit 85d20e034a
18 changed files with 567 additions and 390 deletions
+3 -3
View File
@@ -16,17 +16,17 @@ class AdminAuth implements IMiddleware
// No token
if ($token === null) {
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["code" => "Unauthorized", "message" => "Not Authorized"]);
}
try {
$user = User::getByToken($token);
if (!$user->getIsAdmin()) {
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["code" => "Unauthorized", "message" => "Not Authorized"]);
}
} catch (Exception $err) {
// No user with this token exists
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["code" => "Unauthorized", "message" => "Not Authorized"]);
}
}
}
+2 -2
View File
@@ -16,14 +16,14 @@ class Auth implements IMiddleware
// No token
if ($token === null) {
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["code" => "Unauthorized", "message" => "Not Authorized"]);
}
try {
User::getByToken($token);
} catch (Exception $err) {
// No user with this token exists
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["code" => "Unauthorized", "message" => "Not Authorized"]);
}
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ class OptAuth implements IMiddleware
User::getByToken($token);
} catch (Exception $err) {
// No user with this token exists
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["code" => "Unauthorized", "message" => "Not Authorized"]);
}
}
}