Completed
Push — master ( c915d2...2ad4b2 )
by Alexander
04:32
created

ThrowsApiErrors::failedValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Flugg\Responder\Traits;
4
5
use Illuminate\Contracts\Validation\Validator;
6
use Flugg\Responder\Exceptions\UnauthorizedException;
7
use Flugg\Responder\Exceptions\ValidationFailedException;
8
9
10
/**
11
 * Use this trait in your base form request to override the exceptions thrown when
12
 * validation or authorization fails. This allows the package to render proper
13
 * API responses through the HandlesApiErrors trait.
14
 *
15
 * @package Laravel Responder
16
 * @author  Alexander Tømmerås <[email protected]>
17
 * @license The MIT License
18
 */
19
trait ThrowsApiErrors
20
{
21
    /**
22
     * Handle a failed validation attempt.
23
     *
24
     * @param  \Illuminate\Contracts\Validation\Validator $validator
25
     * @return void
26
     * @throws ValidationFailedException
27
     */
28
    protected function failedValidation( Validator $validator )
29
    {
30
        throw new ValidationFailedException( $validator );
31
    }
32
33
    /**
34
     * Handle a failed authorization attempt.
35
     *
36
     * @return void
37
     * @throws UnauthorizedException
38
     */
39
    protected function failedAuthorization()
40
    {
41
        throw new UnauthorizedException();
42
    }
43
}