Handle sourcenotfoundexception and targetnotmentionedexception
This commit is contained in:
parent
51f1269600
commit
fca08de828
12
index.php
12
index.php
@ -5,11 +5,13 @@ require_once __DIR__ . "/vendor/autoload.php";
|
||||
use Lewisdale\Webmentions\Endpoint;
|
||||
use Lewisdale\Webmentions\Exceptions\InvalidTargetException;
|
||||
use Lewisdale\Webmentions\Exceptions\InvalidUrlException;
|
||||
use Lewisdale\Webmentions\Gateways\SqliteGateway;
|
||||
use Lewisdale\Webmentions\Router\Request;
|
||||
use Lewisdale\Webmentions\Router\Router;
|
||||
use Lewisdale\Webmentions\Router\Response;
|
||||
use Lewisdale\Webmentions\Router\Router;
|
||||
use Lewisdale\Webmentions\Router\StatusCode;
|
||||
use Lewisdale\Webmentions\Webmention;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
|
||||
$router = new Router();
|
||||
|
||||
@ -23,7 +25,7 @@ $router->post("/endpoint", function(Request $req, Response $response) {
|
||||
$source = $req->post['source'];
|
||||
$target = $req->post['target'];
|
||||
|
||||
$endpoint = new Endpoint();
|
||||
$endpoint = new Endpoint(HttpClient::create(), new SqliteGateway("webmentions.db"));
|
||||
|
||||
try {
|
||||
$endpoint->receiveWebmention($source, $target);
|
||||
@ -33,6 +35,12 @@ $router->post("/endpoint", function(Request $req, Response $response) {
|
||||
} catch (InvalidTargetException $e) {
|
||||
$response->status_code = StatusCode::BadRequest;
|
||||
return "Target must be on the domain lewisdale.dev";
|
||||
} catch (\Lewisdale\Webmentions\Exceptions\SourceNotFoundException $e) {
|
||||
$response->status_code = StatusCode::BadRequest;
|
||||
return "Source URL was unreachable";
|
||||
} catch (\Lewisdale\Webmentions\Exceptions\TargetNotMentionedException) {
|
||||
$response->status_code = StatusCode::BadRequest;
|
||||
return "Source does not mention the target";
|
||||
}
|
||||
|
||||
$response->status_code = StatusCode::Created;
|
||||
|
Loading…
Reference in New Issue
Block a user