Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
HttpDownloadException
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getHttpStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResponseBody
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResponseHeaders
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * HTTP download exception
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2022.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Exceptions
25 * @author   Mario Trojan <mario.trojan@uni-tuebingen.de>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\Exception;
31
32use Laminas\Http\Headers;
33
34/**
35 * "Format Unavailable" Exception
36 *
37 * @category VuFind
38 * @package  Exceptions
39 * @author   Mario Trojan <mario.trojan@uni-tuebingen.de>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org/wiki/development Wiki
42 */
43class HttpDownloadException extends \Exception implements HttpStatusInterface
44{
45    /**
46     * URL we tried to download.
47     *
48     * @var string
49     */
50    protected $url;
51
52    /**
53     * HTTP status associated with this exception.
54     *
55     * @var ?int
56     */
57    protected $statusCode;
58
59    /**
60     * HTTP response headers associated with this exception.
61     *
62     * @var ?Headers
63     */
64    protected $responseHeaders;
65
66    /**
67     * HTTP response body associated with this exception.
68     *
69     * @var ?string
70     */
71    protected $responseBody;
72
73    /**
74     * Constructor
75     *
76     * @param string          $message         Exception message
77     * @param string          $url             URL we tried to download
78     * @param int|null        $statusCode      HTTP status code
79     * @param Headers|null    $responseHeaders HTTP response headers
80     * @param string|null     $responseBody    HTTP response body
81     * @param \Throwable|null $previous        Previous exception
82     */
83    public function __construct(
84        string $message,
85        string $url,
86        ?int $statusCode = null,
87        ?Headers $responseHeaders = null,
88        ?string $responseBody = null,
89        ?\Throwable $previous = null
90    ) {
91        $this->url = $url;
92        $this->statusCode = $statusCode;
93        $this->responseHeaders = $responseHeaders;
94        $this->responseBody = $responseBody;
95        parent::__construct($message, 0, $previous);
96    }
97
98    /**
99     * Get HTTP status associated with this exception.
100     *
101     * @return ?int
102     */
103    public function getHttpStatus(): ?int
104    {
105        return $this->statusCode;
106    }
107
108    /**
109     * Get HTTP response body.
110     *
111     * @return ?string
112     */
113    public function getResponseBody(): ?string
114    {
115        return $this->responseBody;
116    }
117
118    /**
119     * Get HTTP response headers.
120     *
121     * @return ?Headers
122     */
123    public function getResponseHeaders(): ?Headers
124    {
125        return $this->responseHeaders;
126    }
127
128    /**
129     * Get URL we tried to download.
130     *
131     * @return string
132     */
133    public function getUrl(): string
134    {
135        return $this->url;
136    }
137}