Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LibresignException | |
85.71% |
6 / 7 |
|
66.67% |
2 / 3 |
5.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHttpStatus | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Exception; |
| 10 | |
| 11 | use JsonSerializable; |
| 12 | use OCP\AppFramework\Http; |
| 13 | |
| 14 | class LibresignException extends \Exception implements JsonSerializable { |
| 15 | /** |
| 16 | * @param int|null $httpStatus status of the HTTP response built from this |
| 17 | * exception; when null, the code is used as the |
| 18 | * status, as callers did before this argument existed |
| 19 | */ |
| 20 | public function __construct( |
| 21 | string $message = '', |
| 22 | int $code = 0, |
| 23 | ?\Throwable $previous = null, |
| 24 | private ?int $httpStatus = null, |
| 25 | ) { |
| 26 | parent::__construct($message, $code, $previous); |
| 27 | } |
| 28 | |
| 29 | public function getHttpStatus(): int { |
| 30 | if ($this->httpStatus !== null) { |
| 31 | return $this->httpStatus; |
| 32 | } |
| 33 | if ($this->getCode() === 0) { |
| 34 | return Http::STATUS_UNPROCESSABLE_ENTITY; |
| 35 | } |
| 36 | return (int)$this->getCode(); |
| 37 | } |
| 38 | |
| 39 | #[\Override] |
| 40 | public function jsonSerialize(): mixed { |
| 41 | return ['message' => $this->getMessage()]; |
| 42 | } |
| 43 | } |