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

Errors   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 17
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleNotFound() 0 7 2
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
}