Skip to content
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
4 changes: 3 additions & 1 deletion src/Mouf/Mvc/Splash/Controllers/Http500HandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Mouf\Mvc\Splash\Controllers;
use Psr\Http\Message\ServerRequestInterface;

/**
* Classes implementing this interface can be used when a HTTP 500 error is triggered.
Expand All @@ -15,6 +16,7 @@ interface Http500HandlerInterface
* This function is called when a HTTP 404 error is triggered by the user.
*
* @param \Exception $exception
* @param ServerRequestInterface $request
*/
public function serverError(\Exception $exception);
public function serverError(\Exception $exception, ServerRequestInterface $request);
}
12 changes: 11 additions & 1 deletion src/Mouf/Mvc/Splash/Controllers/HttpErrorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Mouf\Html\Template\TemplateInterface;
use Mouf\Html\HtmlElement\HtmlElementInterface;
use Mouf\Mvc\Splash\HtmlResponse;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\JsonResponse;

/**
* This class provides the default Splash behaviour when a HTTP 404 and HTTP 500 error is triggered.
Expand Down Expand Up @@ -96,9 +98,15 @@ public function pageNotFound($message)
*
* @see Mouf\Mvc\Splash\Controllers.Http500HandlerInterface::serverError()
*/
public function serverError(\Exception $exception)
public function serverError(\Exception $exception, ServerRequestInterface $request)
{
$this->exception = $exception;

$acceptType = $request->getHeader('Accept');
if (is_array($acceptType) && count($acceptType) > 0 && strpos($acceptType[0], "json") !== false ){
return new JsonResponse(["error" => ["message" => $exception->getMessage(), "type" => "Exception", "trace" => $this->debugMode ? $exception->getTraceAsString() : ""]]);
}

if ($this->contentFor500) {
$this->contentBlock = $this->contentFor500;
} else {
Expand All @@ -108,6 +116,8 @@ public function serverError(\Exception $exception)
return HtmlResponse::create($this->template, 500);
}



/**
* Inludes the file (useful to load a view inside the Controllers scope).
*
Expand Down