Skip to content

Commit

Permalink
add notfound error code, slight refactor to obfio.php
Browse files Browse the repository at this point in the history
  • Loading branch information
brookgagnon committed Aug 19, 2024
1 parent 419f61a commit f555c89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions classes/core/obfio.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
*/
class OBFIO
{
private $use_http_status = false;

public function __construct()
{
if (str_starts_with($_SERVER['REQUEST_URI'], '/api/v2/')) {
$this->use_http_status = true;
}
}

/**
Expand Down Expand Up @@ -59,7 +64,7 @@ public function error($error_no)
{
$user = OBFUser::get_instance();

if (str_starts_with($_SERVER['REQUEST_URI'], '/api/v2/')) {
if ($this->use_http_status) {
http_response_code(400);
}

Expand All @@ -77,10 +82,17 @@ public function error($error_no)
break;

case OB_ERROR_DENIED:
if ($this->use_http_status) {
http_response_code(403);
}
$msg = 'Access denied.';
if (str_starts_with($_SERVER['REQUEST_URI'], '/api/v2/')) {
http_response_code(401);
break;

case OB_ERROR_NOTFOUND:
if ($this->use_http_status) {
http_response_code(404);
}
$msg = 'Not found.';
break;
}

Expand Down
3 changes: 3 additions & 0 deletions components.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
if (!defined('OB_ERROR_DENIED')) {
define('OB_ERROR_DENIED', 4);
}
if (!defined('OB_ERROR_NOTFOUND')) {
define('OB_ERROR_NOTFOUND', 5);
}
if (!defined('OB_LOCAL')) {
define('OB_LOCAL', __DIR__);
}
Expand Down

0 comments on commit f555c89

Please sign in to comment.