Skip to content

Commit fb793be

Browse files
authored
Rename Interfaces\ErrorHandlerInterface to Errors\HandlerInterface (#72)
* Rename error handler interface * update readme and add docs
1 parent 68529e6 commit fb793be

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Other auto-detected container entries:
9898
| Psr\Log\LoggerInterface | Internal logging | generated front controller |
9999
| Firehed\API\Authentication\ProviderInterface | Authentication Provider | Always if an AuthorizationProvider is set |
100100
| Firehed\API\Authorization\ProviderInterface | Authorization Provider | Always if an AuthenticationProvider is set |
101-
| Firehed\API\Interfaces\ErrorHandlerInterface | Error Handler | Always |
101+
| Firehed\API\Errors\HandlerInterface | Error Handler | Always |
102102

103103

104104
### Example
@@ -160,7 +160,7 @@ The API framework is responsible for catching all exceptions thrown during an En
160160
All endpoints that implement `Firehed\API\Interfaces\HandlesOwnErrorsInterface` (which is a part of `EndpointInterface` prior to v4.0.0) will have their `handleException()` method called with the thrown exception.
161161
This method _may_ choose to ignore certain exception classes (by rethrowing them), but must return a PSR `ResponseInterface` when opting to handle an exception.
162162

163-
Starting in v3.1.0, error handling can be implemeneted globally by providing a `Firehed\API\Interfaces\ErrorHandlerInterface` to the Dispatcher via `setErrorHandler()`.
163+
Starting in v3.1.0, error handling can be implemeneted globally by providing a `Firehed\API\Errors\HandlerInterface` to the Dispatcher via `setErrorHandler()`.
164164
This is functionally identical to `HandlesOwnErrorInterface` described above, with the addition that the PSR `ServerRequestInterface` will also be available (primarily so that the response can be formatted appropriately for the request, e.g. based on the `Accept` header).
165165

166166
Finally, a global fallback handler is configured by default, which will log the exception and return a generic 500 error.

src/Dispatcher.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use BadMethodCallException;
88
use DomainException;
9-
use Firehed\API\Interfaces\ErrorHandlerInterface;
9+
use Firehed\API\Errors\HandlerInterface;
1010
use Firehed\API\Interfaces\HandlesOwnErrorsInterface;
1111
use Firehed\Common\ClassMapper;
1212
use Firehed\Input\Containers\ParsedInput;
@@ -109,8 +109,8 @@ public function setContainer(ContainerInterface $container = null): self
109109
}
110110

111111
// Auto-detect error handler
112-
if (!$this->error_handler && $container->has(ErrorHandlerInterface::class)) {
113-
$this->setErrorHandler($container->get(ErrorHandlerInterface::class));
112+
if (!$this->error_handler && $container->has(HandlerInterface::class)) {
113+
$this->setErrorHandler($container->get(HandlerInterface::class));
114114
}
115115

116116
return $this;
@@ -120,10 +120,10 @@ public function setContainer(ContainerInterface $container = null): self
120120
* Provide a default error handler. This will be used in the event that an
121121
* endpoint does not define its own handler.
122122
*
123-
* @param ErrorHandlerInterface $handler
123+
* @param HandlerInterface $handler
124124
* @return self
125125
*/
126-
public function setErrorHandler(ErrorHandlerInterface $handler): self
126+
public function setErrorHandler(HandlerInterface $handler): self
127127
{
128128
$this->error_handler = $handler;
129129
return $this;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Firehed\API\Interfaces;
4+
namespace Firehed\API\Errors;
55

66
use Psr\Http\Message\ResponseInterface;
77
use Psr\Http\Message\ServerRequestInterface;
88
use Throwable;
99

10-
interface ErrorHandlerInterface
10+
/**
11+
* Implementations of this interface are for application-wide error handling.
12+
* See the section on error handling in the README for additional information.
13+
*/
14+
interface HandlerInterface
1115
{
1216
/**
1317
* Handle an exception for the given request. It is RECOMMENDED that

tests/DispatcherTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Firehed\API\Authentication;
99
use Firehed\API\Authorization;
1010
use Firehed\API\Interfaces\EndpointInterface;
11-
use Firehed\API\Interfaces\ErrorHandlerInterface;
11+
use Firehed\API\Errors\HandlerInterface;
1212
use Psr\Container\ContainerInterface;
1313
use Psr\Http\Message\RequestInterface;
1414
use Psr\Http\Message\ResponseInterface;
@@ -567,7 +567,7 @@ public function testExceptionsReachDefaultErrorHandlerWhenSet()
567567
return $res;
568568
};
569569

570-
$handler = $this->createMock(ErrorHandlerInterface::class);
570+
$handler = $this->createMock(HandlerInterface::class);
571571
$handler->expects($this->once())
572572
->method('handle')
573573
->will($this->returnCallback($cb));
@@ -687,7 +687,7 @@ public function testAuthComponentsAreAutoDetected()
687687
public function testErrorHandlerIsAutoDetected()
688688
{
689689
$ex = new Exception('execute');
690-
$eh = $this->createMock(ErrorHandlerInterface::class);
690+
$eh = $this->createMock(HandlerInterface::class);
691691
$eh->expects($this->once())
692692
->method('handle')
693693
->will($this->returnCallback(function ($sri, $caught) use ($ex) {
@@ -703,7 +703,7 @@ public function testErrorHandlerIsAutoDetected()
703703
});
704704

705705
$container = $this->getMockContainer([
706-
ErrorHandlerInterface::class => $eh,
706+
HandlerInterface::class => $eh,
707707
'ClassThatDoesNotExist' => $ep,
708708
]);
709709
$req = $this->getMockRequestWithUriPath('/c', 'GET', [], ServerRequestInterface::class);

0 commit comments

Comments
 (0)