Completed
Push — master ( ca3a05...58f804 )
by André
66:34 queued 43:18
created

ServerException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 9.6666
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
        parent::__construct($error->message, $error->code);
30
31
        // These are only set if server is running in debug mode, but even if not set we want to overwrite the values.
32
        $this->file = (string)$error->file;
33
        $this->line = (int)$error->line;
34
        $this->trace = explode("\n", (array)$error->trace);
35
    }
36
}
37