Completed
Pull Request — master (#6)
by Janis
03:08
created

Errors::handleNotFound()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * nextCloud - ocr
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Janis Koehr <[email protected]>
9
 * @copyright Janis Koehr 2016
10
 */
11
namespace OCA\Ocr\Controller;
12
13
use Closure;
14
15
use OCP\AppFramework\Http;
16
use OCP\AppFramework\Http\DataResponse;
17
18
use OCA\Ocr\Service\NotFoundException;
19
20
21
/**
22
 * Class Errors
23
 * @package OCA\Ocr\Controller
24
 */
25
trait Errors {
26
27
	/**
28
	 * handles the thrown Errors for all Controllers
29
	 * and sends a DataResponse with the ErrorMessage of the service
30
	 * @param Closure $callback
31
	 * @return DataResponse
32
	 */
33
	protected function handleNotFound (Closure $callback) {
34
		try {
35
			return new DataResponse($callback());
36
		} catch(NotFoundException $e) {
37
			return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND);
38
		}
39
	}
40
41
}