Merge pull request #735 from cachethq/api-exceptions

Make sure only "application/*" error pages are returned from the api
This commit is contained in:
Graham Campbell
2015-06-17 10:00:57 +01:00
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Exceptions\Filters;
use Exception;
use Illuminate\Http\Request;
class ApiFilter
{
/**
* The request instance.
*
* @var \Illuminate\Http\Request
*/
protected $request;
/**
* Create a new content type filter instance.
*
* @param \Illuminate\Http\Request $request
*
* @return void
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* Filter and return the displayers.
*
* @param \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[] $displayers
* @param \Exception $exception
*
* @return \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[]
*/
public function filter(array $displayers, Exception $exception)
{
if ($this->request->is('api*')) {
foreach ($displayers as $index => $displayer) {
if (!str_contains($displayer->contentType(), 'application/')) {
unset($displayers[$index]);
}
}
}
return array_values($displayers);
}
}

View File

@@ -48,6 +48,7 @@ return [
'GrahamCampbell\Exceptions\Filters\VerboseFilter',
'GrahamCampbell\Exceptions\Filters\CanDisplayFilter',
'GrahamCampbell\Exceptions\Filters\ContentTypeFilter',
'CachetHQ\Cachet\Exceptions\Filters\ApiFilter',
],
];