Errors::respond()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace OCA\Notes\Controller;
4
5
use OCP\AppFramework\Http;
6
use OCP\AppFramework\Http\DataResponse;
7
8
use OCA\Notes\Service\NoteDoesNotExistException;
9
10
/**
11
 * Class Errors
12
 *
13
 * @package OCA\Notes\Controller
14
 */
15
trait Errors {
16
	/**
17
	 * @param $callback
18
	 * @return DataResponse
19
	 */
20
	protected function respond($callback) {
21
		try {
22
			return new DataResponse($callback());
23
		} catch (NoteDoesNotExistException $ex) {
24
			return new DataResponse([], Http::STATUS_NOT_FOUND);
25
		}
26
	}
27
}
28