. namespace core\router; use Psr\Http\Message\ServerRequestInterface; use Slim\App; use Slim\Handlers\ErrorHandler; /** * An Eerror Handler implementation for Moodle which is aware of the REST API. * * @package core * @copyright Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class error_handler extends ErrorHandler { /** * Construct a new Error Handler. * * @param \Slim\App $app */ public function __construct( App $app, ) { parent::__construct( $app->getCallableResolver(), $app->getResponseFactory(), ); $this->registerErrorRenderer('text/html', error_renderer::class); } #[\Override] protected function determineContentType(ServerRequestInterface $request): ?string { // For anything hitting /rest/api/v2 we will default to JSON. $restbase = (new \core\url('/rest/api/v2/'))->get_path(); if (substr($request->getUri()->getPath(), 0, strlen($restbase)) === $restbase) { return 'application/json'; } // Fall back to the default behaviour of using the Accept header. return parent::determineContentType($request); } }