Response::generateResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Nextcloud - Tasks
4
 *
5
 * @author Raimund Schlüßler
6
 * @copyright 2018 Raimund Schlüßler <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Tasks\Controller;
24
25
use \Closure;
26
use \OCP\AppFramework\Http\JSONResponse;
27
28
trait Response {
29
	protected function generateResponse(Closure $callback) {
30
		try {
31
			$message = [
32
				'status' => 'success',
33
				'data' => $callback(),
34
				'message' => null
35
			];
36
		} catch (\Exception $e) {
37
			$message = [
38
				'status' => 'error',
39
				'data' => null,
40
				'message' => $e->getMessage()
41
			];
42
		}
43
		return new JSONResponse($message);
44
	}
45
}
46