-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathErrorResponse.php
More file actions
52 lines (46 loc) · 1.35 KB
/
ErrorResponse.php
File metadata and controls
52 lines (46 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Mindee\Parsing\V2;
use Mindee\Error\ErrorItem;
/**
* Error response class.
*/
class ErrorResponse
{
/**
* @var integer The HTTP status code returned by the server.
*/
public int $status;
/**
* @var string A human-readable explanation specific to the occurrence of the problem.
*/
public string $detail;
/**
* @var string|null A short, human-readable summary of the problem.
*/
public ?string $title;
/**
* @var string|null A machine-readable code specific to the occurrence of the problem.
*/
public ?string $code;
/**
* @var array|mixed|null A list of explicit error details.
*/
public ?array $errors;
/**
* @param array $serverResponse Raw server response array.
*/
public function __construct(array $serverResponse)
{
$this->status = $serverResponse['status'];
$this->detail = $serverResponse['detail'];
$this->title = $serverResponse['title'] ?? null;
$this->code = $serverResponse['code'] ?? null;
if (isset($serverResponse['errors']) && is_array($serverResponse['errors'])) {
$this->errors = array_map(static function ($error) {
return new ErrorItem($error);
}, $serverResponse['errors']);
} else {
$this->errors = [];
}
}
}