]> git.mxchange.org Git - friendica.git/commitdiff
Replace System::httpExit() by HTTPException throwing
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 03:16:10 +0000 (23:16 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 15:37:09 +0000 (11:37 -0400)
39 files changed:
mod/bookmarklet.php
mod/cal.php
mod/dfrn_notify.php
mod/dfrn_poll.php
mod/display.php
mod/fetch.php
mod/follow.php
mod/hcard.php
mod/help.php
mod/hovercard.php
mod/notice.php
mod/poco.php
mod/probe.php
mod/pubsub.php
mod/pubsubhubbub.php
mod/receive.php
mod/salmon.php
mod/search.php
mod/viewcontacts.php
mod/viewsrc.php
src/BaseModule.php
src/Model/Profile.php
src/Module/Attach.php
src/Module/Feed.php
src/Module/Followers.php
src/Module/Following.php
src/Module/Group.php
src/Module/Inbox.php
src/Module/Install.php
src/Module/NodeInfo.php
src/Module/Objects.php
src/Module/Outbox.php
src/Module/Photo.php
src/Module/Profile.php
src/Module/Proxy.php
src/Module/Statistics.php
src/Module/WebFinger.php
src/Module/Xrd.php
src/Protocol/Diaspora.php

index 1c4d191c4f8d1fa21b89e4d6194cb915be585dc9..f15d12d6d1b82bb67b1308fc0d8f25dd4eb025b7 100644 (file)
@@ -29,7 +29,7 @@ function bookmarklet_content(App $a)
 
        if (!strstr($referer, $page)) {
                if (empty($_REQUEST["url"])) {
-                       System::httpExit(400, ["title" => L10n::t('Bad Request')]);
+                       throw new \Friendica\Network\HTTPException\BadRequestException(L10n::t('This page is missing a url parameter.'));
                }
 
                $content = add_page_info($_REQUEST["url"]);
index 5baffec8a8f423cbfaf30d45739ecbf9f9bcc180..ce6d501ffe0c3922f2aaaca4638d1ba999947506 100644 (file)
@@ -31,11 +31,11 @@ function cal_init(App $a)
        }
 
        if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
-               System::httpExit(403, ['title' => L10n::t('Access denied.')]);
+               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
        }
 
        if ($a->argc < 2) {
-               System::httpExit(403, ['title' => L10n::t('Access denied.')]);
+               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
        }
 
        Nav::setSelected('events');
@@ -43,7 +43,7 @@ function cal_init(App $a)
        $nick = $a->argv[1];
        $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
        if (!DBA::isResult($user)) {
-               System::httpExit(404, ['title' => L10n::t('Page not found.')]);
+               throw new \Slim\Exception\NotFoundException();
        }
 
        $a->data['user'] = $user;
index 745411a8ef89ec10f9f8263fda1db1a30f3355d0..1a9f98fa33103f8f411a9ebd6d12dca36bee812d 100644 (file)
@@ -29,7 +29,7 @@ function dfrn_notify_post(App $a) {
 
                        $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]);
                        if (!DBA::isResult($user)) {
-                               System::httpExit(500);
+                               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
                        }
                        dfrn_dispatch_private($user, $postdata);
                } elseif (!dfrn_dispatch_public($postdata)) {
index 5b72c0bf940cec4fa7d4ac0c643430c9b1e4c425..6c849cb807fa6b28059991e51e6207cb9a85aa84 100644 (file)
@@ -50,7 +50,7 @@ function dfrn_poll_init(App $a)
 
        if (($dfrn_id === '') && empty($_POST['dfrn_id'])) {
                if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
-                       System::httpExit(403);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
                $user = '';
@@ -59,7 +59,7 @@ function dfrn_poll_init(App $a)
                                DBA::escape($a->argv[1])
                        );
                        if (!$r) {
-                               System::httpExit(404);
+                               throw new \Friendica\Network\HTTPException\NotFoundException();
                        }
 
                        $hidewall = ($r[0]['hidewall'] && !local_user());
@@ -483,7 +483,7 @@ function dfrn_poll_content(App $a)
                        // heluecht: I don't know why we don't fail immediately when the user or contact hadn't been found.
                        // Since it doesn't make sense to continue from this point on, we now fail here. This should be safe.
                        if (!DBA::isResult($r)) {
-                               System::httpExit(404, ["title" => L10n::t('Page not found.')]);
+                               throw new \Friendica\Network\HTTPException\NotFoundException();
                        }
 
                        // URL reply
index acc2a5b0901540466009bb60e6066c28fc63e274..fa5b2e1962d3d0df161315f6010a4074d52f3f64 100644 (file)
@@ -20,6 +20,7 @@ use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Module\Objects;
+use Friendica\Network\HTTPException;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\DFRN;
 use Friendica\Util\Strings;
@@ -76,7 +77,7 @@ function display_init(App $a)
        }
 
        if (!DBA::isResult($item)) {
-               System::httpExit(404);
+               return;
        }
 
        if ($a->argc >= 3 && $nick == 'feed-item') {
@@ -200,8 +201,7 @@ function display_fetchauthor($a, $item)
 function display_content(App $a, $update = false, $update_uid = 0)
 {
        if (Config::get('system','block_public') && !local_user() && !remote_user()) {
-               notice(L10n::t('Public access denied.') . EOL);
-               return;
+               throw new HTTPException\ForbiddenException(L10n::t('Public access denied.'));
        }
 
        $o = '';
@@ -254,7 +254,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
        }
 
        if (!$item_id) {
-               System::httpExit(404);
+               throw new HTTPException\NotFoundException(L10n::t('The requested item doesn\'t exist or has been deleted.'));
        }
 
        // We are displaying an "alternate" link if that post was public. See issue 2864
@@ -303,8 +303,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
        $is_owner = (local_user() && (in_array($a->profile['profile_uid'], [local_user(), 0])) ? true : false);
 
        if (!empty($a->profile['hidewall']) && !$is_owner && !$is_remote_contact) {
-               notice(L10n::t('Access to this profile has been restricted.') . EOL);
-               return;
+               throw new HTTPException\ForbiddenException(L10n::t('Access to this profile has been restricted.'));
        }
 
        // We need the editor here to be able to reshare an item.
@@ -340,7 +339,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
        $item = Item::selectFirstForUser(local_user(), $fields, $condition);
 
        if (!DBA::isResult($item)) {
-               System::httpExit(404);
+               throw new HTTPException\NotFoundException(L10n::t('The requested item doesn\'t exist or has been deleted.'));
        }
 
        $item['uri'] = $item['parent-uri'];
@@ -415,7 +414,7 @@ function displayShowFeed($item_id, $conversation)
 {
        $xml = DFRN::itemFeed($item_id, $conversation);
        if ($xml == '') {
-               System::httpExit(500);
+               throw new HTTPException\InternalServerErrorException(L10n::t('The feed for this item is unavailable.'));
        }
        header("Content-type: application/atom+xml");
        echo $xml;
index 3e9c4e662671ee4422de37a0c59e37d22d0506d0..492f319efbb5b713c035ee23a59122634620a728 100644 (file)
@@ -14,9 +14,8 @@ use Friendica\Database\DBA;
 
 function fetch_init(App $a)
 {
-
        if (($a->argc != 3) || (!in_array($a->argv[1], ["post", "status_message", "reshare"]))) {
-               System::httpExit(404);
+               throw new \Friendica\Network\HTTPException\NotFoundException();
        }
 
        $guid = $a->argv[2];
@@ -42,13 +41,13 @@ function fetch_init(App $a)
                        }
                }
 
-               System::httpExit(404);
+               throw new \Friendica\Network\HTTPException\NotFoundException();
        }
 
        // Fetch some data from the author (We could combine both queries - but I think this is more readable)
        $user = User::getOwnerDataById($item["uid"]);
        if (!$user) {
-               System::httpExit(404);
+               throw new \Friendica\Network\HTTPException\NotFoundException();
        }
 
        $status = Diaspora::buildStatus($item, $user);
index ba4ff35f1923e0556ae6f1451781f41bef778b65..e0b6e1733b7386b420f0efb221e9a9b59abed75f 100644 (file)
@@ -17,7 +17,7 @@ use Friendica\Util\Strings;
 function follow_post(App $a)
 {
        if (!local_user()) {
-               System::httpExit(403, ['title' => L10n::t('Access denied.')]);
+               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
        }
 
        if (isset($_REQUEST['cancel'])) {
index e27ea29be4b0f8bc5c3e645aee2a38619a8deda9..828eeaf0910a3fdd5338d529eb49fbc6bb51283e 100644 (file)
@@ -17,8 +17,7 @@ function hcard_init(App $a)
        if ($a->argc > 1) {
                $which = $a->argv[1];
        } else {
-               notice(L10n::t('No profile') . EOL);
-               return;
+               throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('No profile'));
        }
 
        $profile = 0;
index cdfedac6ffedfabc26ea8598d5e610d0d50fe08c..19b629271ecb304f611f149e94128c483e4faad6 100644 (file)
@@ -62,11 +62,7 @@ function help_content(App $a)
        }
 
        if (!strlen($text)) {
-               header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
-               $tpl = Renderer::getMarkupTemplate("404.tpl");
-               return Renderer::replaceMacros($tpl, [
-                       '$message' => L10n::t('Page not found.')
-               ]);
+               throw new \Friendica\Network\HTTPException\NotFoundException();
        }
 
        $html = Markdown::convert($text, false);
index 603c617ca4874107efb6833db9585405371f1570..ca399196368b71b3151d616924b8e59a8ab19cca 100644 (file)
@@ -31,7 +31,7 @@ function hovercard_content()
 
        // Get out if the system doesn't have public access allowed
        if (intval(Config::get('system', 'block_public'))) {
-               System::httpExit(401);
+               throw new \Friendica\Network\HTTPException\ForbiddenException();
        }
 
        // Return the raw content of the template. We use this to make templates usable for js functions.
index edcbefdad2321d1e3515566e94f217fa3c4d9a33..b0a6a543912d71e656ed0b403695a293b4654fa7 100644 (file)
@@ -16,7 +16,7 @@ function notice_init(App $a)
                $nick = $r[0]['nickname'];
                $a->internalRedirect('display/' . $nick . '/' . $id);
        } else {
-               notice(L10n::t('Item not found.') . EOL);
+               throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item not found.'));
        }
 
        return;
index 064e0e9a85f919178aefcd6372a4092efd324a69..c288f6b6393bf8a7bf3eb082b8714cb3dc4a914a 100644 (file)
@@ -22,7 +22,7 @@ function poco_init(App $a) {
        $system_mode = false;
 
        if (intval(Config::get('system', 'block_public')) || (Config::get('system', 'block_local_dir'))) {
-               System::httpExit(401);
+               throw new \Friendica\Network\HTTPException\ForbiddenException();
        }
 
        if ($a->argc > 1) {
@@ -31,7 +31,7 @@ function poco_init(App $a) {
        if (empty($nickname)) {
                $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1");
                if (!DBA::isResult($c)) {
-                       System::httpExit(401);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
                $system_mode = true;
        }
@@ -73,7 +73,7 @@ function poco_init(App $a) {
                        DBA::escape($nickname)
                );
                if (! DBA::isResult($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $user = $users[0];
@@ -371,8 +371,9 @@ function poco_init(App $a) {
                        $ret['entry'][] = [];
                }
        } else {
-               System::httpExit(500);
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
        }
+
        Logger::log("End of poco", Logger::DEBUG);
 
        if ($format === 'xml') {
@@ -385,6 +386,6 @@ function poco_init(App $a) {
                echo json_encode($ret);
                exit();
        } else {
-               System::httpExit(500);
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
        }
 }
index e120ce17246dbbc37647842494e5c80b4d419ee4..7fc3a92899f78be6314116e23775b0389189c366 100644 (file)
@@ -10,9 +10,9 @@ use Friendica\Network\Probe;
 function probe_content(App $a)
 {
        if (!local_user()) {
-               System::httpExit(403, ["title" => L10n::t("Public access denied."),
-                       "description" => L10n::t("Only logged in users are permitted to perform a probing.")]);
-               exit();
+               $e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a probing."));
+               $e->httpdesc = L10n::t("Public access denied.");
+               throw $e;
        }
 
        $o = '<div class="generic-page-wrapper">';
index c5744f399b2443565525eb0293ef090f1a7875a0..e5ede6c80a3792da91512c2d95f8db61d52dd51d 100644 (file)
@@ -12,10 +12,9 @@ use Friendica\Core\System;
 function hub_return($valid, $body)
 {
        if ($valid) {
-               header($_SERVER["SERVER_PROTOCOL"] . ' 200 OK');
                echo $body;
        } else {
-               System::httpExit(404);
+               throw new \Friendica\Network\HTTPException\NotFoundException();
        }
        exit();
 }
@@ -24,7 +23,7 @@ function hub_return($valid, $body)
 
 function hub_post_return()
 {
-       System::httpExit(200);
+       throw new \Friendica\Network\HTTPException\OKException();
 }
 
 function pubsub_init(App $a)
index 342facd1076fa8b2c03cd56e9c5fb2d090c68c42..f71984ec1826cfce2a5df6492f17bdc4b841f759 100644 (file)
@@ -17,7 +17,7 @@ function pubsubhubbub_init(App $a) {
        // PuSH subscription must be considered "public" so just block it
        // if public access isn't enabled.
        if (Config::get('system', 'block_public')) {
-               System::httpExit(403);
+               throw new \Friendica\Network\HTTPException\ForbiddenException();
        }
 
        // Subscription request from subscriber
@@ -44,7 +44,7 @@ function pubsubhubbub_init(App $a) {
                        $subscribe = 0;
                } else {
                        Logger::log("Invalid hub_mode=$hub_mode, ignoring.");
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                Logger::log("$hub_mode request from " . $_SERVER['REMOTE_ADDR']);
@@ -61,7 +61,7 @@ function pubsubhubbub_init(App $a) {
 
                if (!$nick) {
                        Logger::log('Bad hub_topic=$hub_topic, ignoring.');
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // fetch user from database given the nickname
@@ -69,13 +69,13 @@ function pubsubhubbub_init(App $a) {
                $owner = DBA::selectFirst('user', ['uid', 'hidewall', 'nickname'], $condition);
                if (!DBA::isResult($owner)) {
                        Logger::log('Local account not found: ' . $nick . ' - topic: ' . $hub_topic . ' - callback: ' . $hub_callback);
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // abort if user's wall is supposed to be private
                if ($owner['hidewall']) {
                        Logger::log('Local user ' . $nick . 'has chosen to hide wall, ignoring.');
-                       System::httpExit(403);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
                // get corresponding row from contact table
@@ -84,7 +84,7 @@ function pubsubhubbub_init(App $a) {
                $contact = DBA::selectFirst('contact', ['poll'], $condition);
                if (!DBA::isResult($contact)) {
                        Logger::log('Self contact for user ' . $owner['uid'] . ' not found.');
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // sanity check that topic URLs are the same
@@ -93,7 +93,7 @@ function pubsubhubbub_init(App $a) {
 
                if (!Strings::compareLink($hub_topic, $contact['poll']) && !Strings::compareLink($hub_topic2, $contact['poll']) && !Strings::compareLink($hub_topic, $self)) {
                        Logger::log('Hub topic ' . $hub_topic . ' != ' . $contact['poll']);
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // do subscriber verification according to the PuSH protocol
@@ -121,19 +121,19 @@ function pubsubhubbub_init(App $a) {
                // give up if the HTTP return code wasn't a success (2xx)
                if ($ret < 200 || $ret > 299) {
                        Logger::log("Subscriber verification for $hub_topic at $hub_callback returned $ret, ignoring.");
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // check that the correct hub_challenge code was echoed back
                if (trim($body) !== $hub_challenge) {
                        Logger::log("Subscriber did not echo back hub.challenge, ignoring.");
                        Logger::log("\"$hub_challenge\" != \"".trim($body)."\"");
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                PushSubscriber::renew($owner['uid'], $nick, $subscribe, $hub_callback, $hub_topic, $hub_secret);
 
-               System::httpExit(202);
+               throw new \Friendica\Network\HTTPException\AcceptedException();
        }
        exit();
 }
index b0258acbd71803b0ac4286cafd31eb5c465d065b..db1287ea6f1f804a8b6b784710ce5e01409beb07 100644 (file)
@@ -22,7 +22,7 @@ function receive_post(App $a)
        $enabled = intval(Config::get('system', 'diaspora_enabled'));
        if (!$enabled) {
                Logger::log('mod-diaspora: disabled');
-               System::httpExit(500);
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
        }
 
        if (($a->argc == 2) && ($a->argv[1] === 'public')) {
@@ -32,13 +32,13 @@ function receive_post(App $a)
                $public = false;
 
                if ($a->argc != 3 || $a->argv[1] !== 'users') {
-                       System::httpExit(500);
+                       throw new \Friendica\Network\HTTPException\InternalServerErrorException();
                }
                $guid = $a->argv[2];
 
                $importer = DBA::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
                if (!DBA::isResult($importer)) {
-                       System::httpExit(500);
+                       throw new \Friendica\Network\HTTPException\InternalServerErrorException();
                }
        }
 
@@ -49,7 +49,7 @@ function receive_post(App $a)
        if (empty($_POST['xml'])) {
                $postdata = file_get_contents("php://input");
                if ($postdata == '') {
-                       System::httpExit(500);
+                       throw new \Friendica\Network\HTTPException\InternalServerErrorException();
                }
 
                Logger::log('mod-diaspora: message is in the new format', Logger::DEBUG);
@@ -71,7 +71,7 @@ function receive_post(App $a)
        Logger::log('mod-diaspora: decoded msg: ' . print_r($msg, true), Logger::DATA);
 
        if (!is_array($msg)) {
-               System::httpExit(500);
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
        }
 
        Logger::log('mod-diaspora: dispatching', Logger::DEBUG);
@@ -83,6 +83,9 @@ function receive_post(App $a)
                $ret = Diaspora::dispatch($importer, $msg);
        }
 
-       System::httpExit(($ret) ? 200 : 500);
-       // NOTREACHED
+       if ($ret) {
+               throw new \Friendica\Network\HTTPException\OKException();
+       } else {
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
+       }
 }
index 84d2942d5332dd5d8e042bff24a73569d7100eb4..ba1bc8d46513e54caf0c58be55487e5a0387b79c 100644 (file)
@@ -28,7 +28,7 @@ function salmon_post(App $a, $xml = '') {
                DBA::escape($nick)
        );
        if (! DBA::isResult($r)) {
-               System::httpExit(500);
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
        }
 
        $importer = $r[0];
@@ -49,7 +49,7 @@ function salmon_post(App $a, $xml = '') {
 
        if (empty($base)) {
                Logger::log('unable to locate salmon data in xml ');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        // Stash the signature away for now. We have to find their key or it won't be good for anything.
@@ -87,7 +87,7 @@ function salmon_post(App $a, $xml = '') {
 
        if(! $author_link) {
                Logger::log('Could not retrieve author URI.');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        // Once we have the author URI, go to the web and try to find their public key
@@ -98,7 +98,7 @@ function salmon_post(App $a, $xml = '') {
 
        if(! $key) {
                Logger::log('Could not retrieve author key.');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        $key_info = explode('.',$key);
@@ -130,7 +130,7 @@ function salmon_post(App $a, $xml = '') {
 
        if (! $verify) {
                Logger::log('Message did not verify. Discarding.');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        Logger::log('Message verified with mode '.$mode);
@@ -177,8 +177,7 @@ function salmon_post(App $a, $xml = '') {
        //if((DBA::isResult($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == Contact::FOLLOWER) || ($r[0]['blocked']))) {
        if (DBA::isResult($r) && $r[0]['blocked']) {
                Logger::log('Ignoring this author.');
-               System::httpExit(202);
-               // NOTREACHED
+               throw new \Friendica\Network\HTTPException\AcceptedException();
        }
 
        // Placeholder for hub discovery.
@@ -188,5 +187,5 @@ function salmon_post(App $a, $xml = '') {
 
        OStatus::import($data, $importer, $contact_rec, $hub);
 
-       System::httpExit(200);
+       throw new \Friendica\Network\HTTPException\OKException();
 }
index 9a70bcac908d179d3512761284bd8dd64b431a17..1416f1d89f52d34edb82e9a94da5af8e91353779 100644 (file)
@@ -98,12 +98,9 @@ function search_content(App $a) {
        }
 
        if (Config::get('system','local_search') && !local_user() && !remote_user()) {
-               System::httpExit(403,
-                               ["title" => L10n::t("Public access denied."),
-                                       "description" => L10n::t("Only logged in users are permitted to perform a search.")]);
-               exit();
-               //notice(L10n::t('Public access denied.').EOL);
-               //return;
+               $e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a search."));
+               $e->httpdesc = L10n::t("Public access denied.");
+               throw $e;
        }
 
        if (Config::get('system','permit_crawling') && !local_user() && !remote_user()) {
@@ -123,10 +120,7 @@ function search_content(App $a) {
                if (!is_null($result)) {
                        $resultdata = json_decode($result);
                        if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
-                               System::httpExit(429,
-                                               ["title" => L10n::t("Too Many Requests"),
-                                                       "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]);
-                               exit();
+                               throw new \Friendica\Network\HTTPException\TooManyRequestsException(L10n::t("Only one search per minute is permitted for not logged in users."));
                        }
                        Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), Cache::HOUR);
                } else
index 7c2b96fad1bb796cd0b8fe32d2eb23fe5db3d3aa..14919820dd2f280b3024fcc03814e8740c35e8d2 100644 (file)
@@ -20,18 +20,18 @@ use Friendica\Util\Proxy as ProxyUtils;
 function viewcontacts_init(App $a)
 {
        if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
-               System::httpExit(403, ["title" => L10n::t('Access denied.')]);
+               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
        }
 
        if ($a->argc < 2) {
-               System::httpExit(403, ["title" => L10n::t('Access denied.')]);
+               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
        }
 
        Nav::setSelected('home');
 
        $user = DBA::selectFirst('user', [], ['nickname' => $a->argv[1], 'blocked' => false]);
        if (!DBA::isResult($user)) {
-               System::httpExit(404, ["title" => L10n::t('Page not found.')]);
+               throw new \Friendica\Network\HTTPException\NotFoundException();
        }
 
        $a->data['user'] = $user;
index 939c73a142e21bb509240639c212a8244526bb14..55eb0b990c06ca5f2e44978b1e01450162f86fd9 100644 (file)
@@ -18,8 +18,7 @@ function viewsrc_content(App $a)
        $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
 
        if (!$item_id) {
-               notice(L10n::t('Item not found.') . EOL);
-               return;
+               throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item not found.'));
        }
 
        $item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $item_id]);
index 3878d150734720d8d2b6d42b16245ec04e6088d8..dd9059bfba0db063fa3732b1969eacd42620da73 100644 (file)
@@ -153,7 +153,7 @@ abstract class BaseModule extends BaseObject
                        Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
                        Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
 
-                       System::httpExit(403);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
        }
 }
index 3c4ca6fed5a66aca2b55495da4f9e8e767bfe428..13156a93285531786bcfad5488f93e153226b674 100644 (file)
@@ -112,7 +112,6 @@ class Profile
 
                if (!DBA::isResult($user) && empty($profiledata)) {
                        Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
-                       notice(L10n::t('Requested account is not available.') . EOL);
                        return;
                }
 
@@ -129,7 +128,6 @@ class Profile
 
                if (empty($pdata) && empty($profiledata)) {
                        Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
-                       notice(L10n::t('Requested profile is not available.') . EOL);
                        return;
                }
 
index 24e0edc5552ad774d7187573249835acd31474b7..e9af90facc3fb1b0cc053acb93909e238c962e91 100644 (file)
@@ -24,7 +24,7 @@ class Attach extends BaseModule
        {
                $a = self::getApp();
                if ($a->argc != 2) {
-                       System::httpExit(400); // Bad Request.
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                // @TODO: Replace with parameter from router
@@ -33,19 +33,19 @@ class Attach extends BaseModule
                // Check for existence
                $item = MAttach::exists(['id' => $item_id]);
                if ($item === false) {
-                       System::httpExit(404, ['description' => L10n::t('Item was not found.')]);
+                       throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item was not found.'));
                }
 
                // Now we'll fetch the item, if we have enough permisson
                $item = MAttach::getByIdWithPermission($item_id);
                if ($item === false) {
-                       System::httpExit(403, ['description' => L10n::t('Permission denied.')]);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Permission denied.'));
                }
 
                $data = MAttach::getData($item);
                if (is_null($data)) {
                        Logger::log('NULL data for attachment with id ' . $item['id']);
-                       System::httpExit(404, ['description' => L10n::t('Item was not found.')]);
+                       throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item was not found.'));
                }
 
                // Use quotes around the filename to prevent a "multiple Content-Disposition"
index eabd45da23eef073fef2af295390a2b3bdd4fa0a..ba1b085963d9d2afb99d37506d5e7aca39530ea8 100644 (file)
@@ -33,7 +33,7 @@ class Feed extends BaseModule
 
                // @TODO: Replace with parameter from router
                if ($a->argc < 2) {
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                $type = null;
index 9906dfc33e3b2882ee0da885a523da6ad97fd354..79f34021b13243ebc883b01106cbf31b92d46a1c 100644 (file)
@@ -20,13 +20,13 @@ class Followers extends BaseModule
 
                // @TODO: Replace with parameter from router
                if (empty($a->argv[1])) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // @TODO: Replace with parameter from router
                $owner = User::getOwnerDataByNick($a->argv[1]);
                if (empty($owner)) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $page = defaults($_REQUEST, 'page', null);
index 670142c4897ad0c261c9853aef6cbdeff3a82f72..3a68e7e0afbd9bb21852e878e2decbd718e6e0ad 100644 (file)
@@ -20,13 +20,13 @@ class Following extends BaseModule
 
                // @TODO: Replace with parameter from router
                if (empty($a->argv[1])) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                // @TODO: Replace with parameter from router
                $owner = User::getOwnerDataByNick($a->argv[1]);
                if (empty($owner)) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $page = defaults($_REQUEST, 'page', null);
index eb1389d799e33d5c27d2d15f1264306ba0dd5cba..acc969c7e025f8bab6fe75bc4a043b1c8d77d502 100644 (file)
@@ -137,7 +137,7 @@ class Group extends BaseModule
                $change = false;
 
                if (!local_user()) {
-                       System::httpExit(403);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
                $a = self::getApp();
@@ -276,7 +276,7 @@ class Group extends BaseModule
                }
 
                if (!isset($group)) {
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                $groupeditor = [
index 35160bd88d03a4e92f0ae8afec80187e732a00d5..5367adb7e1c8f9e53f55920b7cecc72ec37ab31f 100644 (file)
@@ -25,7 +25,7 @@ class Inbox extends BaseModule
                $postdata = file_get_contents('php://input');
 
                if (empty($postdata)) {
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                if (Config::get('debug', 'ap_inbox_log')) {
@@ -43,7 +43,7 @@ class Inbox extends BaseModule
                if (!empty($a->argv[1])) {
                        $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
                        if (!DBA::isResult($user)) {
-                               System::httpExit(404);
+                               throw new \Friendica\Network\HTTPException\NotFoundException();
                        }
                        $uid = $user['uid'];
                } else {
@@ -52,6 +52,6 @@ class Inbox extends BaseModule
 
                ActivityPub\Receiver::processInbox($postdata, $_SERVER, $uid);
 
-               System::httpExit(202);
+               throw new \Friendica\Network\HTTPException\AcceptedException();
        }
 }
index 1cef8fbafa5ac63a24d2693d8311e9abb6020eff..eae018fe1671633f6c212427dbb8719a96282730 100644 (file)
@@ -51,7 +51,7 @@ class Install extends BaseModule
                $a = self::getApp();
 
                if (!$a->getMode()->isInstall()) {
-                       Core\System::httpExit(403);
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
                // route: install/testrwrite
@@ -59,7 +59,7 @@ class Install extends BaseModule
                // @TODO: Replace with parameter from router
                if ($a->getArgumentValue(1, '') == 'testrewrite') {
                        // Status Code 204 means that it worked without content
-                       Core\System::httpExit(204);
+                       throw new \Friendica\Network\HTTPException\NoContentException();
                }
 
                self::$installer = new Core\Installer();
index c8d75b8e16f0ffa45a7d0e971a33465217e554c5..3261ef690241b33ddbd47696fb2265c11a1b2a0b 100644 (file)
@@ -18,7 +18,7 @@ class NodeInfo extends BaseModule
                $config = self::getApp()->getConfig();
 
                if (!$config->get('system', 'nodeinfo')) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
        }
 
@@ -41,14 +41,14 @@ class NodeInfo extends BaseModule
         *
         * @param App $app
         *
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \Friendica\Network\HTTPException\NotFoundException
         */
        private static function printWellKnown(App $app)
        {
                $config = $app->getConfig();
 
                if (!$config->get('system', 'nodeinfo')) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $nodeinfo = [
index f34af3a08044af329836ff00b937bf93b92a8c4e..2104e8042fd98e3c2cc9f7bc57eb9782a7627826 100644 (file)
@@ -20,7 +20,7 @@ class Objects extends BaseModule
                $a = self::getApp();
 
                if (empty($a->argv[1])) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                if (!ActivityPub::isRequest()) {
@@ -38,7 +38,7 @@ class Objects extends BaseModule
                        // @TODO: Replace with parameter from router
                        $item = Item::selectFirst(['id', 'author-link'], ['guid' => $a->argv[1], 'private' => false]);
                        if (!DBA::isResult($item) || !strstr($item['author-link'], System::baseUrl())) {
-                               System::httpExit(404);
+                               throw new \Friendica\Network\HTTPException\NotFoundException();
                        }
                }
 
index 27dcd5c1f44b905b51423e6f3cccc3bfe8e43e6b..14825677910919e92a50833d6866bbeb1b16f5c9 100644 (file)
@@ -20,12 +20,12 @@ class Outbox extends BaseModule
 
                // @TODO: Replace with parameter from router
                if (empty($a->argv[1])) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $owner = User::getOwnerDataByNick($a->argv[1]);
                if (empty($owner)) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $page = defaults($_REQUEST, 'page', null);
index 9165af8bedbbaad213c98833563887df25849d64..bcfe13f5372e4330a2650f15caa8225a3109ab66 100644 (file)
@@ -6,6 +6,7 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
+use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Model\Photo as MPhoto;
@@ -27,7 +28,7 @@ class Photo extends BaseModule
                $a = self::getApp();
                // @TODO: Replace with parameter from router
                if ($a->argc <= 1 || $a->argc > 4) {
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
@@ -74,9 +75,7 @@ class Photo extends BaseModule
                }
 
                if ($photo === false) {
-                       // not using System::httpExit() because we don't want html here.
-                       header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found" , true, 404);
-                       exit();
+                       System::httpExit('404', 'Not Found');
                }
 
                $cacheable = ($photo["allow_cid"] . $photo["allow_gid"] . $photo["deny_cid"] . $photo["deny_gid"] === "") && (isset($photo["cacheable"]) ? $photo["cacheable"] : true);
@@ -85,7 +84,7 @@ class Photo extends BaseModule
 
                if (is_null($img) || !$img->isValid()) {
                        Logger::log("Invalid photo with id {$photo["id"]}.");
-                       System::httpExit(500, ["description" => "Invalid photo with id {$photo["id"]}."]);
+                       throw new \Friendica\Network\HTTPException\InternalServerErrorException(L10n::t('Invalid photo with id %s.', $photo["id"]));
                }
 
                // if customsize is set and image is not a gif, resize it
index c3297d261a295ec9a8abc368f983aa1833f30d71..fceea726b4cfe863d203673dbf11095810c0595b 100644 (file)
@@ -38,7 +38,7 @@ class Profile extends BaseModule
 
                // @TODO: Replace with parameter from router
                if ($a->argc < 2) {
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                self::$which = filter_var($a->argv[1], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
index 387667a1a5a20c58e9cc6d246b3e501a7af620e7..75a1142af6221331ce4715d3a87c7f8988a7c44f 100644 (file)
@@ -70,7 +70,7 @@ class Proxy extends BaseModule
                $request = self::getRequestInfo();
 
                if (empty($request['url'])) {
-                       System::httpExit(400, ['title' => L10n::t('Bad Request.')]);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                // Webserver already tried direct cache...
index 566ace333144e4d0066b7cbbdd57d132f3951b6a..3e64828e7b64b3dfe33897d9dad3dd85e703b4f7 100644 (file)
@@ -13,7 +13,7 @@ class Statistics extends BaseModule
                $config = self::getApp()->getConfig();
 
                if (!$config->get("system", "nodeinfo")) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
        }
 
index 3afcecb0565706c7254b1bea1c163f80a4d40077..0c1a692e1b14d5436530f68d749007ce72a84118 100644 (file)
@@ -5,7 +5,6 @@ namespace Friendica\Module;
 use Friendica\BaseModule;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
-use Friendica\Core\System;
 use Friendica\Network\Probe;
 
 /**
@@ -13,22 +12,14 @@ use Friendica\Network\Probe;
  */
 class WebFinger extends BaseModule
 {
-       public static function init()
+       public static function content()
        {
                if (!local_user()) {
-                       System::httpExit(
-                               403,
-                               [
-                                       'title'       => L10n::t('Public access denied.'),
-                                       'description' => L10n::t('Only logged in users are permitted to perform a probing.'),
-                               ],
-                       );
-                       exit();
+                       $e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a probing."));
+                       $e->httpdesc = L10n::t("Public access denied.");
+                       throw $e;
                }
-       }
 
-       public static function content()
-       {
                $app = self::getApp();
 
                $addr = defaults($_GET, 'addr', '');
index 38ce151ff87e9eb0f827836042c8eb103775d576..a3b161d1898bf2c04904799d1ab1920337d54d12 100644 (file)
@@ -58,7 +58,7 @@ class Xrd extends BaseModule
                $user = User::getByNickname($name);
 
                if (empty($user)) {
-                       System::httpExit(404);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
                }
 
                $profileURL = $app->getBaseURL() . '/profile/' . $user['nickname'];
index 33cbb2659d8aabeec6e9d246ae4a39089f467bf6..3a7e73cee56b56bf49d841e0e1e34a0183632331 100644 (file)
@@ -400,7 +400,7 @@ class Diaspora
                                if ($no_exit) {
                                        return false;
                                } else {
-                                       System::httpExit(400);
+                                       throw new \Friendica\Network\HTTPException\BadRequestException();
                                }
                        }
 
@@ -419,7 +419,7 @@ class Diaspora
                        if ($no_exit) {
                                return false;
                        } else {
-                               System::httpExit(400);
+                               throw new \Friendica\Network\HTTPException\BadRequestException();
                        }
                }
 
@@ -445,7 +445,7 @@ class Diaspora
                        if ($no_exit) {
                                return false;
                        } else {
-                               System::httpExit(400);
+                               throw new \Friendica\Network\HTTPException\BadRequestException();
                        }
                }
 
@@ -455,7 +455,7 @@ class Diaspora
                        if ($no_exit) {
                                return false;
                        } else {
-                               System::httpExit(400);
+                               throw new \Friendica\Network\HTTPException\BadRequestException();
                        }
                }
 
@@ -465,7 +465,7 @@ class Diaspora
                        if ($no_exit) {
                                return false;
                        } else {
-                               System::httpExit(400);
+                               throw new \Friendica\Network\HTTPException\BadRequestException();
                        }
                }
 
@@ -550,7 +550,7 @@ class Diaspora
 
                if (!$base) {
                        Logger::log('unable to locate salmon data in xml');
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
 
@@ -588,7 +588,7 @@ class Diaspora
 
                if (!$author_link) {
                        Logger::log('Could not retrieve author URI.');
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
                // Once we have the author URI, go to the web and try to find their public key
                // (first this will look it up locally if it is in the fcontact cache)
@@ -599,14 +599,14 @@ class Diaspora
 
                if (!$key) {
                        Logger::log('Could not retrieve author key.');
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                $verify = Crypto::rsaVerify($signed_data, $signature, $key);
 
                if (!$verify) {
                        Logger::log('Message did not verify. Discarding.');
-                       System::httpExit(400);
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
                }
 
                Logger::log('Message verified.');