Skip to content

Commit 6f2b6bf

Browse files
committed
Change generic Exception to project specific one.
1 parent f18905c commit 6f2b6bf

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/Exception.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Pdsinterop\Solid\Resources;
4+
5+
class Exception extends \Exception
6+
{
7+
public static function create(string $error, array $context, \Exception $previous = null): Exception
8+
{
9+
return new static(vsprintf($error, $context), 0, $previous);
10+
}
11+
}

src/Server.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use EasyRdf_Graph as Graph;
77
use Laminas\Diactoros\ServerRequest;
88
use League\Flysystem\FilesystemInterface as Filesystem;
9-
use LogicException;
109
use Psr\Http\Message\ResponseInterface as Response;
1110
use Psr\Http\Message\ServerRequestInterface as Request;
1211
use Throwable;
@@ -147,8 +146,8 @@ private function handle(string $method, string $path, $contents, $request): Resp
147146
// @FIXME: Add correct headers to resources (for instance allow DELETE on a GET resource)
148147
// ->withAddedHeader('Accept-Patch', 'text/ldpatch')
149148
// ->withAddedHeader('Accept-Post', 'text/turtle, application/ld+json, image/bmp, image/jpeg')
150-
// ->withHeader('Allow', 'GET, HEAD, OPTIONS, PATCH, POST, PUT');
151-
// ;
149+
// ->withHeader('Allow', 'GET, HEAD, OPTIONS, PATCH, POST, PUT')
150+
//;
152151

153152
switch ($method) {
154153
case 'DELETE':
@@ -249,8 +248,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
249248
}
250249
break;
251250
default:
252-
$message = vsprintf(self::ERROR_UNKNOWN_HTTP_METHOD, [$method]);
253-
throw new LogicException($message);
251+
throw Exception::create(self::ERROR_UNKNOWN_HTTP_METHOD, [$method]);
254252
break;
255253
}
256254

@@ -303,15 +301,15 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
303301
foreach ($values as $value) {
304302
$count = $graph->delete($resource, $property, $value);
305303
if ($count === 0) {
306-
throw new \Exception("Could not delete a value", 500);
304+
throw new Exception("Could not delete a value", 500);
307305
}
308306
}
309307
}
310308
}
311309
}
312310
break;
313311
default:
314-
throw new \Exception("Unimplemented SPARQL", 500);
312+
throw new Exception("Unimplemented SPARQL", 500);
315313
break;
316314
}
317315
}
@@ -500,6 +498,7 @@ private function getRequestedMimeType($accept)
500498
private function handleReadRequest(Response $response, string $path, $contents, $mime=''): Response
501499
{
502500
$filesystem = $this->filesystem;
501+
503502
if ($path === "/") { // FIXME: this is a patch to make it work for Solid-Nextcloud; we should be able to just list '/';
504503
$contents = $this->listDirectoryAsTurtle($path);
505504
$response->getBody()->write($contents);
@@ -591,7 +590,7 @@ private function listDirectoryAsTurtle($path)
591590
$turtle["<>"]['ldp:contains'][] = $filename;
592591
break;
593592
default:
594-
throw new \Exception("Unknown type", 500);
593+
throw new Exception("Unknown type", 500);
595594
break;
596595
}
597596
}

0 commit comments

Comments
 (0)