blob: 23a88938c19dad8cf868d37a52e67e89ce3a780f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
/**
* ownCloud - galleryplus
*
* 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>
* @author Olivier Paroz <owncloud@interfasys.ch>
*
* @copyright Bernhard Posselt 2014-2015
* @copyright Olivier Paroz 2014-2015
*/
namespace OCA\GalleryPlus\Controller;
use OCP\AppFramework\Http\JSONResponse;
/**
* Our classes extend both Controller and ApiController, so we need to use
* traits to add some common methods
*
* @package OCA\GalleryPlus\Controller
*/
trait JsonHttpError {
/**
* @param \Exception $exception the message that is returned taken from the exception
*
* @param int $code the http error code
*
* @return JSONResponse
*/
public function error(\Exception $exception, $code = 0) {
$message = $exception->getMessage();
if ($code === 0) {
$code = $exception->getCode();
}
return new JSONResponse(
[
'message' => $message,
'success' => false
],
$code
);
}
}
|