Completed
Push — ezp26001-permissions_lookup_re... ( 2e76c0...5b8460 )
by
unknown
25:19
created

ServerException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 10
rs 9.4285
1
<?php
2
3
/**
4
 * File containing the ServerException class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
10
namespace eZ\Publish\Core\REST\Client\Exceptions;
11
12
use eZ\Publish\Core\REST\Client\Values\ErrorMessage;
13
use Exception;
14
15
/**
16
 * Wraps a eZ\Publish\Core\REST\Client\Values\ErrorMessage to provide info from server.
17
 *
18
 * To be used as previous exception when throwing client exceptions for server error response codes.
19
 */
20
class ServerException extends Exception
21
{
22
    protected $trace;
23
24
    /**
25
     * @param ErrorMessage $error
26
     */
27
    public function __construct(ErrorMessage $error)
28
    {
29
        // Use description, this is the exception message from sever, message is only the HTTP status message.
30
        parent::__construct($error->description, $error->code);
31
32
        // These are only set if server is running in debug mode, but even if not set we want to overwrite the values.
33
        $this->file = (string)$error->file;
34
        $this->line = (int)$error->line;
35
        $this->trace = explode("\n", (string)$error->trace);
36
    }
37
}
38