/
ApiException.php
57 lines (44 loc) · 1.14 KB
/
ApiException.php
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
<?php
namespace Alphagov\Notifications\Exception;
use Psr\Http\Message\ResponseInterface;
class ApiException extends NotifyException {
/**
* @var ResponseInterface
*/
private $response;
private $errors;
private $msg;
public function __construct($message, $code, $body, ResponseInterface $response) {
$this->response = $response;
$this->errors = $body["errors"];
$this->msg = '';
foreach ($this->errors as $err) {
$this->msg .= $err['error'] . ': "' . $err['message'] . '"';
}
parent::__construct( $this->msg, $code );
}
/**
* Returns the full response the lead to the exception.
*
* @return ResponseInterface
*/
public function getResponse(){
return $this->response;
}
/**
* Returns an error message summary
*
* @return ResponseInterface
*/
public function getErrorMessage(){
return $this->msg;
}
/**
* Returns the original error messages from the Api.
*
* @return ResponseInterface
*/
public function getErrors(){
return $this->errors;
}
}