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

Commit

Permalink
Merge pull request #36 from fabiocarneiro/feature/error-report-improv…
Browse files Browse the repository at this point in the history
…ement

Error report improvement
  • Loading branch information
weierophinney committed Mar 17, 2016
2 parents 8e40861 + 3d18971 commit 138e4e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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

0 comments on commit 138e4e7

Please sign in to comment.