Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Error report improvement #36

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Exception/InvalidMiddlewareException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @see http://github.com/zendframework/zend-stratigility for the canonical source repository
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-stratigility/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Stratigility\Exception;

use InvalidArgumentException;

class InvalidMiddlewareException extends InvalidArgumentException
{
public static function fromValue($value)
{
$received = gettype($value);

if (is_object($value)) {
$received = get_class($value);
}

return new self(
sprintf(
'Middleware must be callable, %s found',
$received
)
);
}
}
4 changes: 2 additions & 2 deletions src/MiddlewarePipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Zend\Stratigility;

use InvalidArgumentException;
use Zend\Stratigility\Exception\InvalidMiddlewareException;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use SplQueue;
Expand Down Expand Up @@ -108,7 +108,7 @@ public function pipe($path, $middleware = null)

// Ensure we have a valid handler
if (! is_callable($middleware)) {
throw new InvalidArgumentException('Middleware must be callable');
throw InvalidMiddlewareException::fromValue($middleware);
}

$this->pipeline->enqueue(new Route(
Expand Down