| 1 |
<?php |
| 2 |
namespace Aws\Exception; |
| 3 |
|
| 4 |
use Aws\Api\Shape; |
| 5 |
use Aws\CommandInterface; |
| 6 |
use Aws\HasDataTrait; |
| 7 |
use Aws\HasMonitoringEventsTrait; |
| 8 |
use Aws\MonitoringEventsInterface; |
| 9 |
use Aws\ResponseContainerInterface; |
| 10 |
use Aws\ResultInterface; |
| 11 |
use JmesPath\Env as JmesPath; |
| 12 |
use Psr\Http\Message\ResponseInterface; |
| 13 |
use Psr\Http\Message\RequestInterface; |
| 14 |
use Throwable; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class AwsException extends \RuntimeException implements |
| 20 |
MonitoringEventsInterface, |
| 21 |
ResponseContainerInterface, |
| 22 |
\ArrayAccess |
| 23 |
{ |
| 24 |
use HasDataTrait; |
| 25 |
use HasMonitoringEventsTrait; |
| 26 |
|
| 27 |
|
| 28 |
private $response; |
| 29 |
private $request; |
| 30 |
private $result; |
| 31 |
private $command; |
| 32 |
private $requestId; |
| 33 |
private $errorType; |
| 34 |
private $errorCode; |
| 35 |
private $errorShape; |
| 36 |
private $connectionError; |
| 37 |
private $transferInfo; |
| 38 |
private $errorMessage; |
| 39 |
private $maxRetriesExceeded; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function __construct( |
| 49 |
$message, |
| 50 |
CommandInterface $command, |
| 51 |
array $context = [], |
| 52 |
?Throwable $previous = null |
| 53 |
) { |
| 54 |
$this->data = $context['body'] ?? []; |
| 55 |
$this->command = $command; |
| 56 |
$this->response = $context['response'] ?? null; |
| 57 |
$this->request = $context['request'] ?? null; |
| 58 |
$this->requestId = $context['request_id'] ?? null; |
| 59 |
$this->errorType = $context['type'] ?? null; |
| 60 |
$this->errorCode = $context['code'] ?? null; |
| 61 |
$this->errorShape = $context['error_shape'] ?? null; |
| 62 |
$this->connectionError = !empty($context['connection_error']); |
| 63 |
$this->result = $context['result'] ?? null; |
| 64 |
$this->transferInfo = $context['transfer_stats'] ?? []; |
| 65 |
$this->errorMessage = $context['message'] ?? null; |
| 66 |
$this->monitoringEvents = []; |
| 67 |
$this->maxRetriesExceeded = false; |
| 68 |
parent::__construct($message, 0, $previous); |
| 69 |
} |
| 70 |
|
| 71 |
public function __toString() |
| 72 |
{ |
| 73 |
if (!$this->getPrevious()) { |
| 74 |
return parent::__toString(); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
return sprintf( |
| 84 |
"exception '%s' with message '%s'\n\n%s", |
| 85 |
get_class($this), |
| 86 |
$this->getMessage(), |
| 87 |
parent::__toString() |
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public function getCommand() |
| 97 |
{ |
| 98 |
return $this->command; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public function getAwsErrorMessage() |
| 107 |
{ |
| 108 |
return $this->errorMessage; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public function getRequest() |
| 117 |
{ |
| 118 |
return $this->request; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public function getResponse() |
| 127 |
{ |
| 128 |
return $this->response; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public function getResult() |
| 137 |
{ |
| 138 |
return $this->result; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public function isConnectionError() |
| 147 |
{ |
| 148 |
return $this->connectionError; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public function getStatusCode() |
| 157 |
{ |
| 158 |
return $this->response ? $this->response->getStatusCode() : null; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
public function getAwsRequestId() |
| 169 |
{ |
| 170 |
return $this->requestId; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public function getAwsErrorType() |
| 179 |
{ |
| 180 |
return $this->errorType; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public function getAwsErrorCode() |
| 189 |
{ |
| 190 |
return $this->errorCode; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
public function getAwsErrorShape() |
| 199 |
{ |
| 200 |
return $this->errorShape; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public function getTransferInfo($name = null) |
| 213 |
{ |
| 214 |
if (!$name) { |
| 215 |
return $this->transferInfo; |
| 216 |
} |
| 217 |
|
| 218 |
return $this->transferInfo[$name] ?? null; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public function setTransferInfo(array $info) |
| 227 |
{ |
| 228 |
$this->transferInfo = $info; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
public function isMaxRetriesExceeded() |
| 237 |
{ |
| 238 |
return $this->maxRetriesExceeded; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
public function setMaxRetriesExceeded() |
| 245 |
{ |
| 246 |
$this->maxRetriesExceeded = true; |
| 247 |
} |
| 248 |
|
| 249 |
public function hasKey($name) |
| 250 |
{ |
| 251 |
return isset($this->data[$name]); |
| 252 |
} |
| 253 |
|
| 254 |
public function get($key) |
| 255 |
{ |
| 256 |
return $this[$key]; |
| 257 |
} |
| 258 |
|
| 259 |
public function search($expression) |
| 260 |
{ |
| 261 |
return JmesPath::search($expression, $this->toArray()); |
| 262 |
} |
| 263 |
} |