1: <?php
2: namespace Hyperwallet\Exception;
3: use Exception;
4: use Hyperwallet\Response\ErrorResponse;
5:
6: /**
7: * The Hyperwallet exception for api errors
8: *
9: * @package Hyperwallet\Exception
10: */
11: class HyperwalletApiException extends HyperwalletException {
12:
13: /**
14: * The error response
15: *
16: * @var ErrorResponse
17: */
18: private $errorResponse;
19:
20: /**
21: * Related resources
22: *
23: * @var array
24: */
25: private $relatedResources;
26:
27: /**
28: * Creates an instance of the HyperwalletArgumentException
29: *
30: * @param ErrorResponse $errorResponse The error response
31: * @param Exception $previous The original exception
32: */
33: public function __construct(ErrorResponse $errorResponse, Exception $previous) {
34: $message = $errorResponse[0] == null ? "Error message is not defined" : $errorResponse[0]->getMessage();
35: parent::__construct($message, 0, $previous);
36:
37: $this->errorResponse = $errorResponse;
38: $this->relatedResources = $errorResponse[0] == null ? array() : $errorResponse[0]->getRelatedResources();
39: }
40:
41: /**
42: * The error response or null if not available
43: *
44: * @return ErrorResponse
45: */
46: public function getErrorResponse() {
47: return $this->errorResponse;
48: }
49:
50: /**
51: * The related resources or null if not available
52: *
53: * @return array
54: */
55: public function getRelatedResources() {
56: return $this->relatedResources;
57: }
58:
59: }
60: