Errors::handleNotFound()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * Nextcloud - OCR
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 2017
10
 */
11
namespace OCA\Ocr\Controller;
12
13
use Closure;
14
use OCP\AppFramework\Http;
15
use OCP\AppFramework\Http\DataResponse;
16
use OCA\Ocr\Service\NotFoundException;
17
18
19
/**
20
 * Class Errors
21
 * 
22
 * @package OCA\Ocr\Controller
23
 */
24
trait Errors {
25
26
    /**
27
     * handles the thrown Errors for all Controllers
28
     * and sends a DataResponse with the ErrorMessage of the service
29
     * 
30
     * @param Closure $callback            
31
     * @return DataResponse
32
     */
33 12
    protected function handleNotFound(Closure $callback) {
34
        try {
35 12
            return new DataResponse($callback());
36 4
        } catch (NotFoundException $e) {
37 4
            return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND);
38
        }
39
    }
40
}