Skip to content

Commit

Permalink
Throw original exception if debug is enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Mar 4, 2021
1 parent 1102f8f commit dfa4a82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Middleware/GlideMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ADmad\Glide\Exception\ResponseException;
use ADmad\Glide\Exception\SignatureException;
use ADmad\Glide\Response\PsrResponseFactory;
use Cake\Core\Configure;
use Cake\Core\InstanceConfigTrait;
use Cake\Event\EventDispatcherInterface;
use Cake\Event\EventDispatcherTrait;
Expand Down Expand Up @@ -342,6 +343,10 @@ protected function _handleException(ServerRequestInterface $request, $exception)
return $result;
}

if (Configure::read('debug')) {
throw $exception;
}

throw new ResponseException(null, null, $exception);
}
}
15 changes: 15 additions & 0 deletions tests/TestCase/Middleware/GlideMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
use ADmad\Glide\Exception\ResponseException;
use ADmad\Glide\Exception\SignatureException;
use ADmad\Glide\Middleware\GlideMiddleware;
use Cake\Core\Configure;
use Cake\Event\EventManager;
use Cake\Http\Response;
use Cake\Http\ServerRequestFactory;
use Cake\TestSuite\TestCase;
use Cake\Utility\Security;
use League\Flysystem\UnableToRetrieveMetadata;
use League\Glide\ServerFactory;
use League\Glide\Signatures\Signature;
use TestApp\Http\TestRequestHandler;
Expand Down Expand Up @@ -180,15 +182,28 @@ public function testSignatureException()
$middleware->process($request, $this->handler);
}

public function test3rdPartyException()
{
$middleware = new GlideMiddleware($this->config);
$request = ServerRequestFactory::fromGlobals([
'REQUEST_URI' => '/images/non-existent.jpg',
]);

$this->expectException(UnableToRetrieveMetadata::class);
$middleware->process($request, $this->handler);
}

public function testResponseException()
{
$middleware = new GlideMiddleware($this->config);
$request = ServerRequestFactory::fromGlobals([
'REQUEST_URI' => '/images/non-existent.jpg',
]);

Configure::write('debug', false);
$this->expectException(ResponseException::class);
$middleware->process($request, $this->handler);
Configure::write('debug', true);
}

public function testExceptionEventListener()
Expand Down

0 comments on commit dfa4a82

Please sign in to comment.