|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AsyncAws\DynamoDb\Exception; |
| 4 | + |
| 5 | +use AsyncAws\Core\Exception\Http\ClientException; |
| 6 | +use AsyncAws\DynamoDb\ValueObject\AttributeValue; |
| 7 | +use AsyncAws\DynamoDb\ValueObject\CancellationReason; |
| 8 | +use Symfony\Contracts\HttpClient\ResponseInterface; |
| 9 | + |
| 10 | +/** |
| 11 | + * The entire transaction request was canceled. |
| 12 | + * DynamoDB cancels a `TransactWriteItems` request under the following circumstances:. |
| 13 | + * |
| 14 | + * - A condition in one of the condition expressions is not met. |
| 15 | + * - A table in the `TransactWriteItems` request is in a different account or region. |
| 16 | + * - More than one action in the `TransactWriteItems` operation targets the same item. |
| 17 | + * - There is insufficient provisioned capacity for the transaction to be completed. |
| 18 | + * - An item size becomes too large (larger than 400 KB), or a local secondary index (LSI) becomes too large, or a |
| 19 | + * similar validation error occurs because of changes made by the transaction. |
| 20 | + * - There is a user error, such as an invalid data format. |
| 21 | + * |
| 22 | + * DynamoDB cancels a `TransactGetItems` request under the following circumstances: |
| 23 | + * |
| 24 | + * - There is an ongoing `TransactGetItems` operation that conflicts with a concurrent `PutItem`, `UpdateItem`, |
| 25 | + * `DeleteItem` or `TransactWriteItems` request. In this case the `TransactGetItems` operation fails with a |
| 26 | + * `TransactionCanceledException`. |
| 27 | + * - A table in the `TransactGetItems` request is in a different account or region. |
| 28 | + * - There is insufficient provisioned capacity for the transaction to be completed. |
| 29 | + * - There is a user error, such as an invalid data format. |
| 30 | + * |
| 31 | + * > If using Java, DynamoDB lists the cancellation reasons on the `CancellationReasons` property. This property is not |
| 32 | + * > set for other languages. Transaction cancellation reasons are ordered in the order of requested items, if an item |
| 33 | + * > has no error it will have `None` code and `Null` message. |
| 34 | + * |
| 35 | + * Cancellation reason codes and possible error messages: |
| 36 | + * |
| 37 | + * - No Errors: |
| 38 | + * |
| 39 | + * - Code: `None` |
| 40 | + * - Message: `null` |
| 41 | + * |
| 42 | + * - Conditional Check Failed: |
| 43 | + * |
| 44 | + * - Code: `ConditionalCheckFailed` |
| 45 | + * - Message: The conditional request failed. |
| 46 | + * |
| 47 | + * - Item Collection Size Limit Exceeded: |
| 48 | + * |
| 49 | + * - Code: `ItemCollectionSizeLimitExceeded` |
| 50 | + * - Message: Collection size exceeded. |
| 51 | + * |
| 52 | + * - Transaction Conflict: |
| 53 | + * |
| 54 | + * - Code: `TransactionConflict` |
| 55 | + * - Message: Transaction is ongoing for the item. |
| 56 | + * |
| 57 | + * - Provisioned Throughput Exceeded: |
| 58 | + * |
| 59 | + * - Code: `ProvisionedThroughputExceeded` |
| 60 | + * - Messages: |
| 61 | + * |
| 62 | + * - The level of configured provisioned throughput for the table was exceeded. Consider increasing your |
| 63 | + * provisioning level with the UpdateTable API. |
| 64 | + * |
| 65 | + * > This Message is received when provisioned throughput is exceeded is on a provisioned DynamoDB table. |
| 66 | + * |
| 67 | + * - The level of configured provisioned throughput for one or more global secondary indexes of the table was |
| 68 | + * exceeded. Consider increasing your provisioning level for the under-provisioned global secondary indexes with |
| 69 | + * the UpdateTable API. |
| 70 | + * |
| 71 | + * > This message is returned when provisioned throughput is exceeded is on a provisioned GSI. |
| 72 | + * |
| 73 | + * |
| 74 | + * |
| 75 | + * - Throttling Error: |
| 76 | + * |
| 77 | + * - Code: `ThrottlingError` |
| 78 | + * - Messages: |
| 79 | + * |
| 80 | + * - Throughput exceeds the current capacity of your table or index. DynamoDB is automatically scaling your table or |
| 81 | + * index so please try again shortly. If exceptions persist, check if you have a hot key: |
| 82 | + * https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-design.html. |
| 83 | + * |
| 84 | + * > This message is returned when writes get throttled on an On-Demand table as DynamoDB is automatically scaling |
| 85 | + * > the table. |
| 86 | + * |
| 87 | + * - Throughput exceeds the current capacity for one or more global secondary indexes. DynamoDB is automatically |
| 88 | + * scaling your index so please try again shortly. |
| 89 | + * |
| 90 | + * > This message is returned when when writes get throttled on an On-Demand GSI as DynamoDB is automatically |
| 91 | + * > scaling the GSI. |
| 92 | + * |
| 93 | + * |
| 94 | + * |
| 95 | + * - Validation Error: |
| 96 | + * |
| 97 | + * - Code: `ValidationError` |
| 98 | + * - Messages: |
| 99 | + * |
| 100 | + * - One or more parameter values were invalid. |
| 101 | + * - The update expression attempted to update the secondary index key beyond allowed size limits. |
| 102 | + * - The update expression attempted to update the secondary index key to unsupported type. |
| 103 | + * - An operand in the update expression has an incorrect data type. |
| 104 | + * - Item size to update has exceeded the maximum allowed size. |
| 105 | + * - Number overflow. Attempting to store a number with magnitude larger than supported range. |
| 106 | + * - Type mismatch for attribute to update. |
| 107 | + * - Nesting Levels have exceeded supported limits. |
| 108 | + * - The document path provided in the update expression is invalid for update. |
| 109 | + * - The provided expression refers to an attribute that does not exist in the item. |
| 110 | + */ |
| 111 | +final class TransactionCanceledException extends ClientException |
| 112 | +{ |
| 113 | + /** |
| 114 | + * A list of cancellation reasons. |
| 115 | + */ |
| 116 | + private $cancellationReasons; |
| 117 | + |
| 118 | + /** |
| 119 | + * @return CancellationReason[] |
| 120 | + */ |
| 121 | + public function getCancellationReasons(): array |
| 122 | + { |
| 123 | + return $this->cancellationReasons; |
| 124 | + } |
| 125 | + |
| 126 | + protected function populateResult(ResponseInterface $response): void |
| 127 | + { |
| 128 | + $data = $response->toArray(false); |
| 129 | + |
| 130 | + if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) { |
| 131 | + $this->message = $v; |
| 132 | + } |
| 133 | + $this->cancellationReasons = empty($data['CancellationReasons']) ? [] : $this->populateResultCancellationReasonList($data['CancellationReasons']); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @return array<string, AttributeValue> |
| 138 | + */ |
| 139 | + private function populateResultAttributeMap(array $json): array |
| 140 | + { |
| 141 | + $items = []; |
| 142 | + foreach ($json as $name => $value) { |
| 143 | + $items[(string) $name] = AttributeValue::create($value); |
| 144 | + } |
| 145 | + |
| 146 | + return $items; |
| 147 | + } |
| 148 | + |
| 149 | + private function populateResultCancellationReason(array $json): CancellationReason |
| 150 | + { |
| 151 | + return new CancellationReason([ |
| 152 | + 'Item' => !isset($json['Item']) ? null : $this->populateResultAttributeMap($json['Item']), |
| 153 | + 'Code' => isset($json['Code']) ? (string) $json['Code'] : null, |
| 154 | + 'Message' => isset($json['Message']) ? (string) $json['Message'] : null, |
| 155 | + ]); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * @return CancellationReason[] |
| 160 | + */ |
| 161 | + private function populateResultCancellationReasonList(array $json): array |
| 162 | + { |
| 163 | + $items = []; |
| 164 | + foreach ($json as $item) { |
| 165 | + $items[] = $this->populateResultCancellationReason($item); |
| 166 | + } |
| 167 | + |
| 168 | + return $items; |
| 169 | + } |
| 170 | +} |
0 commit comments