mirror of
https://github.com/friendica/friendica
synced 2025-04-22 09:10:10 +00:00
Move System::jsonError to BaseModule->jsonError
- This will ensure headers set in BaseModule->run will be carried in jsonError scenarios - Make BaseApi->checkThrottleLimit an object method to use BaseModule->jsonError - Deprecate jsonError() method in Core\System
This commit is contained in:
parent
81279dad9e
commit
46180d7d5b
11 changed files with 48 additions and 26 deletions
|
@ -510,4 +510,23 @@ abstract class BaseModule implements ICanHandleRequests
|
|||
{
|
||||
$this->httpExit(json_encode($content, $options), ICanCreateResponses::TYPE_JSON, $content_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a non-200 HTTP code response using JSON to encode the content and exit
|
||||
*
|
||||
* @param int $httpCode
|
||||
* @param mixed $content
|
||||
* @param string $content_type
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function jsonError(int $httpCode, $content, string $content_type = 'application/json')
|
||||
{
|
||||
if ($httpCode >= 400) {
|
||||
$this->logger->debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'callstack' => System::callstack(20), 'method' => $this->args->getMethod(), 'agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
|
||||
}
|
||||
|
||||
$this->response->setStatus($httpCode);
|
||||
$this->jsonExit($content, $content_type);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue