Skip to content

Commit 2e06748

Browse files
committed
Added ResponseErrorExceptions
1 parent e416e56 commit 2e06748

File tree

5 files changed

+113
-33
lines changed

5 files changed

+113
-33
lines changed

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"psr-4": {
2222
"Francerz\\Http\\Utils\\": "src/utils",
2323
"Francerz\\Http\\Utils\\Headers\\": "src/headers",
24-
"Francerz\\Http\\Utils\\Constants\\": "src/constants"
24+
"Francerz\\Http\\Utils\\Constants\\": "src/constants",
25+
"Francerz\\Http\\Utils\\Exceptions\\": "src/exceptions"
2526
}
2627
}
2728
}

Diff for: composer.lock

+27-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/exceptions/ClientErrorException.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Francerz\Http\Utils\Exceptions;
4+
5+
use Exception;
6+
use Psr\Http\Message\RequestInterface;
7+
use Psr\Http\Message\ResponseInterface;
8+
use Throwable;
9+
10+
class ClientErrorException extends Exception implements ResponseExceptionInterface
11+
{
12+
private $request;
13+
private $response;
14+
15+
public function __construct(
16+
RequestInterface $request,
17+
ResponseInterface $response,
18+
string $message = '',
19+
int $code = 0,
20+
Throwable $previous = null
21+
) {
22+
parent::__construct($message, $code, $previous);
23+
$this->request = $request;
24+
$this->response = $response;
25+
}
26+
27+
public function getRequest() : RequestInterface
28+
{
29+
return $this->request;
30+
}
31+
32+
public function getResponse() : ResponseInterface
33+
{
34+
return $this->response;
35+
}
36+
}

Diff for: src/exceptions/ResponseExceptionInterface.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Francerz\Http\Utils\Exceptions;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
use Psr\Http\Message\ResponseInterface;
7+
8+
interface ResponseExceptionInterface
9+
{
10+
public function getRequest() : RequestInterface;
11+
public function getResponse() : ResponseInterface;
12+
}

Diff for: src/exceptions/ServerErrorException.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Francerz\Http\Utils\Exceptions;
4+
5+
use Exception;
6+
use Psr\Http\Message\RequestInterface;
7+
use Psr\Http\Message\ResponseInterface;
8+
use Throwable;
9+
10+
class ServerErrorException extends Exception implements ResponseExceptionInterface
11+
{
12+
private $request;
13+
private $response;
14+
15+
public function __construct(
16+
RequestInterface $request,
17+
ResponseInterface $response,
18+
string $message = '',
19+
int $code = 0,
20+
Throwable $previous = null
21+
) {
22+
parent::__construct($message, $code, $previous);
23+
$this->request = $request;
24+
$this->response = $response;
25+
}
26+
27+
public function getRequest() : RequestInterface
28+
{
29+
return $this->request;
30+
}
31+
32+
public function getResponse() : ResponseInterface
33+
{
34+
return $this->response;
35+
}
36+
}

0 commit comments

Comments
 (0)