Completed
Push — rest_bdd_errors ( d93549...822103 )
by André
20:35
created

ServerException::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
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
        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 = $error->file;
33
        $this->line = $error->line;
34
        $this->trace = explode("\n", $error->trace);
35
    }
36
}
37