Skip to content

Commit 468a891

Browse files
committed
Http: Review exception classes
- Rename: - `StreamDetachedException` -> `StreamClosedException` - `StreamInvalidRequestException` -> `InvalidStreamRequestException` - `UploadedFileException` -> `UploadFailedException`
1 parent 165b1b5 commit 468a891

12 files changed

+54
-42
lines changed

src/Toolkit/Http/Exception/HttpServerException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
namespace Salient\Http\Exception;
44

5+
/**
6+
* @api
7+
*/
58
class HttpServerException extends HttpException {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http\Exception;
4+
5+
/**
6+
* @api
7+
*/
8+
class InvalidStreamRequestException extends StreamException {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http\Exception;
4+
5+
/**
6+
* @api
7+
*/
8+
class StreamClosedException extends StreamException {}

src/Toolkit/Http/Exception/StreamDetachedException.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Toolkit/Http/Exception/StreamInvalidRequestException.php

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http\Exception;
4+
5+
/**
6+
* @api
7+
*/
8+
class UploadFailedException extends HttpException {}

src/Toolkit/Http/Exception/UploadedFileException.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Toolkit/Http/Message/MultipartStream.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Psr\Http\Message\StreamInterface as PsrStreamInterface;
66
use Salient\Contract\Http\Message\MultipartStreamInterface;
77
use Salient\Contract\Http\Message\StreamPartInterface;
8-
use Salient\Http\Exception\StreamDetachedException;
9-
use Salient\Http\Exception\StreamInvalidRequestException;
8+
use Salient\Http\Exception\InvalidStreamRequestException;
9+
use Salient\Http\Exception\StreamClosedException;
1010
use Salient\Http\Headers;
1111
use Salient\Http\HttpUtil;
1212
use Salient\Utility\Regex;
@@ -276,7 +276,7 @@ public function write(string $string): int
276276
{
277277
$this->assertIsOpen();
278278

279-
throw new StreamInvalidRequestException('Stream is not writable');
279+
throw new InvalidStreamRequestException('Stream is not writable');
280280
}
281281

282282
/**
@@ -287,7 +287,7 @@ public function seek(int $offset, int $whence = \SEEK_SET): void
287287
$this->assertIsOpen();
288288

289289
if (!$this->IsSeekable) {
290-
throw new StreamInvalidRequestException('Stream is not seekable');
290+
throw new InvalidStreamRequestException('Stream is not seekable');
291291
}
292292

293293
switch ($whence) {
@@ -380,7 +380,7 @@ private function doClose(): void
380380
private function assertIsOpen(): void
381381
{
382382
if (!$this->IsOpen) {
383-
throw new StreamDetachedException('Stream is closed or detached');
383+
throw new StreamClosedException('Stream is closed or detached');
384384
}
385385
}
386386
}

src/Toolkit/Http/Message/ServerRequestUpload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Psr\Http\Message\StreamInterface as PsrStreamInterface;
66
use Psr\Http\Message\UploadedFileInterface as PsrUploadedFileInterface;
7-
use Salient\Http\Exception\UploadedFileException;
7+
use Salient\Http\Exception\UploadFailedException;
88
use Salient\Http\HttpUtil;
99
use Salient\Utility\Exception\InvalidArgumentTypeException;
1010
use Salient\Utility\File;
@@ -94,7 +94,7 @@ public function moveTo(string $targetPath): void
9494
: @move_uploaded_file($this->File, $targetPath);
9595
if ($result === false) {
9696
$error = error_get_last();
97-
throw new UploadedFileException($error['message'] ?? sprintf(
97+
throw new UploadFailedException($error['message'] ?? sprintf(
9898
'Error moving %s to %s',
9999
$this->File,
100100
$targetPath,
@@ -143,15 +143,15 @@ public function getClientMediaType(): ?string
143143
private function assertIsValid(): void
144144
{
145145
if ($this->Error !== \UPLOAD_ERR_OK) {
146-
throw new UploadedFileException(sprintf(
146+
throw new UploadFailedException(sprintf(
147147
'Upload failed (%d: %s)',
148148
$this->Error,
149149
static::ERROR_MESSAGE[$this->Error] ?? '',
150150
));
151151
}
152152

153153
if ($this->IsMoved) {
154-
throw new UploadedFileException('Upload already moved');
154+
throw new UploadFailedException('Upload already moved');
155155
}
156156
}
157157
}

src/Toolkit/Http/Message/Stream.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use Salient\Contract\Http\Message\StreamInterface;
77
use Salient\Contract\Http\Message\StreamPartInterface;
88
use Salient\Contract\Http\HasFormDataFlag;
9-
use Salient\Http\Exception\StreamDetachedException;
9+
use Salient\Http\Exception\InvalidStreamRequestException;
10+
use Salient\Http\Exception\StreamClosedException;
1011
use Salient\Http\Exception\StreamEncapsulationException;
11-
use Salient\Http\Exception\StreamInvalidRequestException;
1212
use Salient\Http\Internal\FormDataEncoder;
1313
use Salient\Utility\Exception\InvalidArgumentTypeException;
1414
use Salient\Utility\File;
@@ -245,7 +245,7 @@ public function write(string $string): int
245245
$this->assertHasStream();
246246

247247
if (!$this->IsWritable) {
248-
throw new StreamInvalidRequestException('Stream is not writable');
248+
throw new InvalidStreamRequestException('Stream is not writable');
249249
}
250250

251251
return File::write($this->Stream, $string, null, $this->Uri);
@@ -304,7 +304,7 @@ private function assertIsSeekable(): void
304304
$this->assertHasStream();
305305

306306
if (!$this->IsSeekable) {
307-
throw new StreamInvalidRequestException('Stream is not seekable');
307+
throw new InvalidStreamRequestException('Stream is not seekable');
308308
}
309309
}
310310

@@ -316,7 +316,7 @@ private function assertIsReadable(): void
316316
$this->assertHasStream();
317317

318318
if (!$this->IsReadable) {
319-
throw new StreamInvalidRequestException('Stream is not readable');
319+
throw new InvalidStreamRequestException('Stream is not readable');
320320
}
321321
}
322322

@@ -326,7 +326,7 @@ private function assertIsReadable(): void
326326
private function assertHasStream(): void
327327
{
328328
if (!$this->Stream) {
329-
throw new StreamDetachedException('Stream is closed or detached');
329+
throw new StreamClosedException('Stream is closed or detached');
330330
}
331331
}
332332
}

0 commit comments

Comments
 (0)