mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Return correct TTRSS error bodies even for HTTP-level errors
TTRSS' error message for these cases (NOT_LOGGED_IN) is not especially helpful, but that's what it returns, so that's what we should return, albeit with correct HTTP status codes.
This commit is contained in:
parent
3a5d346b9c
commit
6e19517593
1 changed files with 9 additions and 4 deletions
|
@ -14,6 +14,11 @@ use JKingWeb\Arsse\REST\Response;
|
|||
class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||
const LEVEL = 14;
|
||||
const VERSION = "17.4";
|
||||
const FATAL_ERR = [
|
||||
'seq' => null,
|
||||
'status' => 1,
|
||||
'content' => ['error' => "NOT_LOGGED_IN"],
|
||||
];
|
||||
const OVVERIDE = [
|
||||
'auth' => ["login"],
|
||||
];
|
||||
|
@ -24,17 +29,17 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
public function dispatch(\JKingWeb\Arsse\REST\Request $req): Response {
|
||||
if ($req->method != "POST") {
|
||||
// only POST requests are allowed
|
||||
return new Response(405, "", "", ["Allow: POST"]);
|
||||
return new Response(405, self::FATAL_ERR, "application/json", ["Allow: POST"]);
|
||||
}
|
||||
if ($req->body) {
|
||||
// only JSON entities are allowed
|
||||
if (!preg_match("<^application/json\b|^$>", $req->type)) {
|
||||
return new Response(415, "", "", ['Accept: application/json']);
|
||||
return new Response(415, self::FATAL_ERR, "application/json", ['Accept: application/json']);
|
||||
}
|
||||
$data = @json_decode($req->body, true);
|
||||
if (json_last_error() != \JSON_ERROR_NONE || !is_array($data)) {
|
||||
// non-JSON input indicates an error
|
||||
return new Response(400);
|
||||
return new Response(400, self::FATAL_ERR);
|
||||
}
|
||||
// layer input over defaults
|
||||
$data = array_merge([
|
||||
|
@ -76,7 +81,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
}
|
||||
} else {
|
||||
// absence of a request body indicates an error
|
||||
return new Response(400);
|
||||
return new Response(400, self::FATAL_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue