Skip to content

Commit

Permalink
Add request object back to error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola committed Feb 1, 2019
1 parent ee9ed9e commit 6f5ec38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/BrancaAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$decoded = $this->decodeToken($token);
} catch (RuntimeException $exception) {
$response = (new ResponseFactory)->createResponse(401);
return $this->processError($response, [
"message" => $exception->getMessage()
]);
return $this->processError(
$request,
$response,
["message" => $exception->getMessage()]
);
}

/* Add decoded token to request as attribute when requested. */
Expand Down Expand Up @@ -214,11 +216,12 @@ private function processAfter(
* Call the error handler if it exists
*/
private function processError(
ServerRequestInterface $request,
ResponseInterface $response,
array $arguments
): ResponseInterface {
if (is_callable($this->options["error"])) {
$handlerResponse = $this->options["error"]($response, $arguments);
$handlerResponse = $this->options["error"]($request, $response, $arguments);
if ($handlerResponse instanceof ResponseInterface) {
return $handlerResponse;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@

class TestErrorHandler
{
//ServerRequestInterface $request,
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
array $arguments
) {
$response->getBody()->write(self::class);
return $response;
}

//ServerRequestInterface $request,
public static function error(
ServerRequestInterface $request,
ResponseInterface $response,
array $arguments
) {
Expand Down

0 comments on commit 6f5ec38

Please sign in to comment.