2018-04-17 04:21:51 +02:00
|
|
|
<?php
|
2018-08-30 23:16:53 +02:00
|
|
|
use Friendica\Core\L10n;
|
2018-04-17 04:21:51 +02:00
|
|
|
|
|
|
|
$container = $slim->getContainer();
|
|
|
|
|
|
|
|
// Error handler based off https://stackoverflow.com/a/48135009/757392
|
|
|
|
$container['errorHandler'] = function () {
|
|
|
|
return function(Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response, Exception $exception)
|
2018-04-17 13:17:25 +02:00
|
|
|
{
|
|
|
|
$responseCode = 500;
|
2018-04-17 04:21:51 +02:00
|
|
|
|
|
|
|
if (is_a($exception, 'Friendica\Network\HTTPException')) {
|
|
|
|
$responseCode = $exception->httpcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors['message'] = $exception->getMessage();
|
|
|
|
|
2018-04-17 13:17:25 +02:00
|
|
|
$errors['responseCode'] = $responseCode;
|
2018-04-17 04:21:51 +02:00
|
|
|
|
2018-04-17 13:17:25 +02:00
|
|
|
return $response
|
|
|
|
->withStatus($responseCode)
|
|
|
|
->withJson($errors);
|
|
|
|
};
|
2018-04-17 04:21:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$container['notFoundHandler'] = function () {
|
2018-04-17 13:17:25 +02:00
|
|
|
return function ()
|
2018-04-17 04:21:51 +02:00
|
|
|
{
|
|
|
|
throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Method not found'));
|
2018-04-17 13:17:25 +02:00
|
|
|
};
|
2018-04-17 04:21:51 +02:00
|
|
|
};
|