PluginProbe
Media Cloud Sync / 1.0.0
Media Cloud Sync v1.0.0
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Exception / AwsException.php

AwsException.php in Media Cloud Sync 1.0.0, at includes/sdk/s3/Aws/Exception/AwsException.php

227 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Exception;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Shape;
6 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
7 use Dudlewebs\WPMCS\s3\Aws\HasDataTrait;
8 use Dudlewebs\WPMCS\s3\Aws\HasMonitoringEventsTrait;
9 use Dudlewebs\WPMCS\s3\Aws\MonitoringEventsInterface;
10 use Dudlewebs\WPMCS\s3\Aws\ResponseContainerInterface;
11 use Dudlewebs\WPMCS\s3\Aws\ResultInterface;
12 use Dudlewebs\WPMCS\s3\JmesPath\Env as JmesPath;
13 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
14 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
15 /**
16 * Represents an AWS exception that is thrown when a command fails.
17 */
18 class AwsException extends \RuntimeException implements MonitoringEventsInterface, ResponseContainerInterface, \ArrayAccess
19 {
20 use HasDataTrait;
21 use HasMonitoringEventsTrait;
22 /** @var ResponseInterface */
23 private $response;
24 private $request;
25 private $result;
26 private $command;
27 private $requestId;
28 private $errorType;
29 private $errorCode;
30 private $errorShape;
31 private $connectionError;
32 private $transferInfo;
33 private $errorMessage;
34 private $maxRetriesExceeded;
35 /**
36 * @param string $message Exception message
37 * @param CommandInterface $command
38 * @param array $context Exception context
39 * @param \Exception $previous Previous exception (if any)
40 */
41 public function __construct($message, CommandInterface $command, array $context = [], \Exception $previous = null)
42 {
43 $this->data = isset($context['body']) ? $context['body'] : [];
44 $this->command = $command;
45 $this->response = isset($context['response']) ? $context['response'] : null;
46 $this->request = isset($context['request']) ? $context['request'] : null;
47 $this->requestId = isset($context['request_id']) ? $context['request_id'] : null;
48 $this->errorType = isset($context['type']) ? $context['type'] : null;
49 $this->errorCode = isset($context['code']) ? $context['code'] : null;
50 $this->errorShape = isset($context['error_shape']) ? $context['error_shape'] : null;
51 $this->connectionError = !empty($context['connection_error']);
52 $this->result = isset($context['result']) ? $context['result'] : null;
53 $this->transferInfo = isset($context['transfer_stats']) ? $context['transfer_stats'] : [];
54 $this->errorMessage = isset($context['message']) ? $context['message'] : null;
55 $this->monitoringEvents = [];
56 $this->maxRetriesExceeded = \false;
57 parent::__construct($message, 0, $previous);
58 }
59 public function __toString()
60 {
61 if (!$this->getPrevious()) {
62 return parent::__toString();
63 }
64 // PHP strangely shows the innermost exception first before the outer
65 // exception message. It also has a default character limit for
66 // exception message strings such that the "next" exception (this one)
67 // might not even get shown, causing developers to attempt to catch
68 // the inner exception instead of the actual exception because they
69 // can't see the outer exception's __toString output.
70 return \sprintf("exception '%s' with message '%s'\n\n%s", \get_class($this), $this->getMessage(), parent::__toString());
71 }
72 /**
73 * Get the command that was executed.
74 *
75 * @return CommandInterface
76 */
77 public function getCommand()
78 {
79 return $this->command;
80 }
81 /**
82 * Get the concise error message if any.
83 *
84 * @return string|null
85 */
86 public function getAwsErrorMessage()
87 {
88 return $this->errorMessage;
89 }
90 /**
91 * Get the sent HTTP request if any.
92 *
93 * @return RequestInterface|null
94 */
95 public function getRequest()
96 {
97 return $this->request;
98 }
99 /**
100 * Get the received HTTP response if any.
101 *
102 * @return ResponseInterface|null
103 */
104 public function getResponse()
105 {
106 return $this->response;
107 }
108 /**
109 * Get the result of the exception if available
110 *
111 * @return ResultInterface|null
112 */
113 public function getResult()
114 {
115 return $this->result;
116 }
117 /**
118 * Returns true if this is a connection error.
119 *
120 * @return bool
121 */
122 public function isConnectionError()
123 {
124 return $this->connectionError;
125 }
126 /**
127 * If available, gets the HTTP status code of the corresponding response
128 *
129 * @return int|null
130 */
131 public function getStatusCode()
132 {
133 return $this->response ? $this->response->getStatusCode() : null;
134 }
135 /**
136 * Get the request ID of the error. This value is only present if a
137 * response was received and is not present in the event of a networking
138 * error.
139 *
140 * @return string|null Returns null if no response was received
141 */
142 public function getAwsRequestId()
143 {
144 return $this->requestId;
145 }
146 /**
147 * Get the AWS error type.
148 *
149 * @return string|null Returns null if no response was received
150 */
151 public function getAwsErrorType()
152 {
153 return $this->errorType;
154 }
155 /**
156 * Get the AWS error code.
157 *
158 * @return string|null Returns null if no response was received
159 */
160 public function getAwsErrorCode()
161 {
162 return $this->errorCode;
163 }
164 /**
165 * Get the AWS error shape.
166 *
167 * @return Shape|null Returns null if no response was received
168 */
169 public function getAwsErrorShape()
170 {
171 return $this->errorShape;
172 }
173 /**
174 * Get all transfer information as an associative array if no $name
175 * argument is supplied, or gets a specific transfer statistic if
176 * a $name attribute is supplied (e.g., 'retries_attempted').
177 *
178 * @param string $name Name of the transfer stat to retrieve
179 *
180 * @return mixed|null|array
181 */
182 public function getTransferInfo($name = null)
183 {
184 if (!$name) {
185 return $this->transferInfo;
186 }
187 return isset($this->transferInfo[$name]) ? $this->transferInfo[$name] : null;
188 }
189 /**
190 * Replace the transfer information associated with an exception.
191 *
192 * @param array $info
193 */
194 public function setTransferInfo(array $info)
195 {
196 $this->transferInfo = $info;
197 }
198 /**
199 * Returns whether the max number of retries is exceeded.
200 *
201 * @return bool
202 */
203 public function isMaxRetriesExceeded()
204 {
205 return $this->maxRetriesExceeded;
206 }
207 /**
208 * Sets the flag for max number of retries exceeded.
209 */
210 public function setMaxRetriesExceeded()
211 {
212 $this->maxRetriesExceeded = \true;
213 }
214 public function hasKey($name)
215 {
216 return isset($this->data[$name]);
217 }
218 public function get($key)
219 {
220 return $this[$key];
221 }
222 public function search($expression)
223 {
224 return JmesPath::search($expression, $this->toArray());
225 }
226 }
227