mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-08-18 20:25:00 +02:00
.github
.tx
appinfo
bin
css
docs
img
js
l10n
lib
AppInfo
Command
Config
Controller
Exceptions
ApiController.php
ApiPayloadTrait.php
Controller.php
ExportController.php
FeedApiController.php
FeedController.php
FolderApiController.php
FolderApiV2Controller.php
FolderController.php
ItemApiController.php
ItemController.php
JSONHttpErrorTrait.php
PageController.php
UtilityApiController.php
Cron
Db
Explore
Fetcher
Hooks
Migration
Plugin
Scraper
Search
Service
Settings
Utility
screenshots
src
templates
tests
.editorconfig
.eslintrc.js
.gitignore
.gitmodules
.mailmap
AUTHORS.md
CHANGELOG.md
CONTRIBUTING.md
COPYING
Makefile
README.md
babel.config.js
composer.json
composer.lock
mkdocs.yml
package-lock.json
package.json
phpstan.neon.dist
phpunit.xml
stylelint.config.js
webpack.config.js
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Nextcloud - News
|
|
*
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
* later. See the COPYING file.
|
|
*
|
|
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
|
* @copyright Bernhard Posselt 2014
|
|
*/
|
|
|
|
namespace OCA\News\Controller;
|
|
|
|
use \OCP\AppFramework\Http\JSONResponse;
|
|
|
|
trait JSONHttpErrorTrait
|
|
{
|
|
/**
|
|
* @param \Exception $exception The exception to report
|
|
* @param int $code The http error code
|
|
* @return JSONResponse
|
|
*/
|
|
public function error(\Exception $exception, int $code)
|
|
{
|
|
return new JSONResponse(['message' => $exception->getMessage()], $code);
|
|
}
|
|
|
|
/**
|
|
* @param \Exception $exception
|
|
* @param int $code
|
|
* @return \OCP\AppFramework\Http\JSONResponse
|
|
*/
|
|
public function errorResponseWithExceptionV2(\Exception $exception, int $code): JSONResponse
|
|
{
|
|
return $this->errorResponseV2(
|
|
$exception->getMessage(),
|
|
$exception->getCode(),
|
|
$code
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param string $message
|
|
* @param int $code
|
|
* @param int $httpStatusCode
|
|
* @return \OCP\AppFramework\Http\JSONResponse
|
|
*/
|
|
public function errorResponseV2(string $message, int $code, int $httpStatusCode): JSONResponse
|
|
{
|
|
return new JSONResponse([
|
|
'error' => [
|
|
'code' => $code,
|
|
'message' => $message,
|
|
]
|
|
], $httpStatusCode);
|
|
}
|
|
}
|