blob: 912fea6371fecff3cc1ddb91ef70970bbbc71e29 (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
|
<?php
namespace Cardinity\Exception;
use Cardinity\Method\ResultObjectInterface;
class Request extends Runtime
{
/** @type ResultObjectInterface */
private $result;
/**
* @param \Exception $previous
* @param ResultObjectInterface $result
*/
public function __construct(\Exception $previous = null, ResultObjectInterface $result = null)
{
$this->message .= ' Response data: ' . serialize($result);
parent::__construct($this->message, $this->code, $previous);
$this->result = $result;
}
/**
* Get result object of particular response
* @return ResultObjectInterface
*/
public function getResult()
{
return $this->result;
}
/**
* List of errors occured
* @return array
*/
public function getErrors()
{
return $this->result->getErrors();
}
/**
* Errors in string form
* @return string
*/
public function getErrorsAsString()
{
$string = '';
foreach ($this->getErrors() as $error) {
$string .= sprintf(
"%s: %s",
$error['field'],
$error['message']
);
if (isset($error['rejected'])) {
$string .= sprintf(" ('%s' given)", $error['rejected']);
}
$string .= ";\n";
}
return trim($string);
}
}
|