Skip to content

Commit 37f6609

Browse files
authored
Generate Exceptions (#921)
* Generate Exceptions * Add documentation on top of class * Leverage the new AwsErrorFactory * Fix __constructor signature in GeneratedException * Fix private vs protected * Generate all methods * Fix things * Add constraint in composer.Json * Add changelog entry
1 parent a09e71e commit 37f6609

33 files changed

+1058
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Changed case of object's properties to camelCase.
88
- Added documentation in class's headers.
9+
- Added Business Exceptions.
910

1011
## 1.2.0
1112

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": "^7.2.5 || ^8.0",
1515
"ext-json": "*",
16-
"async-aws/core": "^1.2"
16+
"async-aws/core": "^1.9"
1717
},
1818
"extra": {
1919
"branch-alias": {

src/Enum/ThrottleReason.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Enum;
4+
5+
final class ThrottleReason
6+
{
7+
public const CALLER_RATE_LIMIT_EXCEEDED = 'CallerRateLimitExceeded';
8+
public const CONCURRENT_INVOCATION_LIMIT_EXCEEDED = 'ConcurrentInvocationLimitExceeded';
9+
public const FUNCTION_INVOCATION_RATE_LIMIT_EXCEEDED = 'FunctionInvocationRateLimitExceeded';
10+
public const RESERVED_FUNCTION_CONCURRENT_INVOCATION_LIMIT_EXCEEDED = 'ReservedFunctionConcurrentInvocationLimitExceeded';
11+
public const RESERVED_FUNCTION_INVOCATION_RATE_LIMIT_EXCEEDED = 'ReservedFunctionInvocationRateLimitExceeded';
12+
13+
public static function exists(string $value): bool
14+
{
15+
return isset([
16+
self::CALLER_RATE_LIMIT_EXCEEDED => true,
17+
self::CONCURRENT_INVOCATION_LIMIT_EXCEEDED => true,
18+
self::FUNCTION_INVOCATION_RATE_LIMIT_EXCEEDED => true,
19+
self::RESERVED_FUNCTION_CONCURRENT_INVOCATION_LIMIT_EXCEEDED => true,
20+
self::RESERVED_FUNCTION_INVOCATION_RATE_LIMIT_EXCEEDED => true,
21+
][$value]);
22+
}
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* You have exceeded your maximum total code size per account. Learn more.
10+
*
11+
* @see https://docs.aws.amazon.com/lambda/latest/dg/limits.html
12+
*/
13+
final class CodeStorageExceededException extends ClientException
14+
{
15+
/**
16+
* The exception type.
17+
*/
18+
private $type;
19+
20+
public function getType(): ?string
21+
{
22+
return $this->type;
23+
}
24+
25+
protected function populateResult(ResponseInterface $response): void
26+
{
27+
$data = $response->toArray(false);
28+
29+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
30+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
31+
$this->message = $v;
32+
}
33+
}
34+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ServerException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* Need additional permissions to configure VPC settings.
10+
*/
11+
final class EC2AccessDeniedException extends ServerException
12+
{
13+
private $type;
14+
15+
public function getType(): ?string
16+
{
17+
return $this->type;
18+
}
19+
20+
protected function populateResult(ResponseInterface $response): void
21+
{
22+
$data = $response->toArray(false);
23+
24+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
25+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
26+
$this->message = $v;
27+
}
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ServerException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* AWS Lambda was throttled by Amazon EC2 during Lambda function initialization using the execution role provided for
10+
* the Lambda function.
11+
*/
12+
final class EC2ThrottledException extends ServerException
13+
{
14+
private $type;
15+
16+
public function getType(): ?string
17+
{
18+
return $this->type;
19+
}
20+
21+
protected function populateResult(ResponseInterface $response): void
22+
{
23+
$data = $response->toArray(false);
24+
25+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
26+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
27+
$this->message = $v;
28+
}
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ServerException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* AWS Lambda received an unexpected EC2 client exception while setting up for the Lambda function.
10+
*/
11+
final class EC2UnexpectedException extends ServerException
12+
{
13+
private $type;
14+
15+
private $ec2ErrorCode;
16+
17+
public function getEc2ErrorCode(): ?string
18+
{
19+
return $this->ec2ErrorCode;
20+
}
21+
22+
public function getType(): ?string
23+
{
24+
return $this->type;
25+
}
26+
27+
protected function populateResult(ResponseInterface $response): void
28+
{
29+
$data = $response->toArray(false);
30+
31+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
32+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
33+
$this->message = $v;
34+
}
35+
$this->ec2ErrorCode = isset($data['EC2ErrorCode']) ? (string) $data['EC2ErrorCode'] : null;
36+
}
37+
}

src/Exception/EFSIOException.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* An error occured when reading from or writing to a connected file system.
10+
*/
11+
final class EFSIOException extends ClientException
12+
{
13+
private $type;
14+
15+
public function getType(): ?string
16+
{
17+
return $this->type;
18+
}
19+
20+
protected function populateResult(ResponseInterface $response): void
21+
{
22+
$data = $response->toArray(false);
23+
24+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
25+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
26+
$this->message = $v;
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* The function couldn't make a network connection to the configured file system.
10+
*/
11+
final class EFSMountConnectivityException extends ClientException
12+
{
13+
private $type;
14+
15+
public function getType(): ?string
16+
{
17+
return $this->type;
18+
}
19+
20+
protected function populateResult(ResponseInterface $response): void
21+
{
22+
$data = $response->toArray(false);
23+
24+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
25+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
26+
$this->message = $v;
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* The function couldn't mount the configured file system due to a permission or configuration issue.
10+
*/
11+
final class EFSMountFailureException extends ClientException
12+
{
13+
private $type;
14+
15+
public function getType(): ?string
16+
{
17+
return $this->type;
18+
}
19+
20+
protected function populateResult(ResponseInterface $response): void
21+
{
22+
$data = $response->toArray(false);
23+
24+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
25+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
26+
$this->message = $v;
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* The function was able to make a network connection to the configured file system, but the mount operation timed out.
10+
*/
11+
final class EFSMountTimeoutException extends ClientException
12+
{
13+
private $type;
14+
15+
public function getType(): ?string
16+
{
17+
return $this->type;
18+
}
19+
20+
protected function populateResult(ResponseInterface $response): void
21+
{
22+
$data = $response->toArray(false);
23+
24+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
25+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
26+
$this->message = $v;
27+
}
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ServerException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* AWS Lambda was not able to create an elastic network interface in the VPC, specified as part of Lambda function
10+
* configuration, because the limit for network interfaces has been reached.
11+
*/
12+
final class ENILimitReachedException extends ServerException
13+
{
14+
private $type;
15+
16+
public function getType(): ?string
17+
{
18+
return $this->type;
19+
}
20+
21+
protected function populateResult(ResponseInterface $response): void
22+
{
23+
$data = $response->toArray(false);
24+
25+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
26+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
27+
$this->message = $v;
28+
}
29+
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* One of the parameters in the request is invalid.
10+
*/
11+
final class InvalidParameterValueException extends ClientException
12+
{
13+
/**
14+
* The exception type.
15+
*/
16+
private $type;
17+
18+
public function getType(): ?string
19+
{
20+
return $this->type;
21+
}
22+
23+
protected function populateResult(ResponseInterface $response): void
24+
{
25+
$data = $response->toArray(false);
26+
27+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
28+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
29+
$this->message = $v;
30+
}
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* The request body could not be parsed as JSON.
10+
*/
11+
final class InvalidRequestContentException extends ClientException
12+
{
13+
/**
14+
* The exception type.
15+
*/
16+
private $type;
17+
18+
public function getType(): ?string
19+
{
20+
return $this->type;
21+
}
22+
23+
protected function populateResult(ResponseInterface $response): void
24+
{
25+
$data = $response->toArray(false);
26+
27+
$this->type = isset($data['Type']) ? (string) $data['Type'] : null;
28+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
29+
$this->message = $v;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)