Skip to content

Commit 501e313

Browse files
committed
started working on user session
1 parent 2ec388b commit 501e313

17 files changed

+615
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Access Denied
7+
*
8+
* Thrown when the Matrix API returns a 403 error code. This indicates that
9+
* the agent whose credentials were used in making this request was not authorized to perform this API call.
10+
*
11+
* @package Exceptions
12+
* @author Alin Ghitu <[email protected]>
13+
*/
14+
class AccessDeniedException extends ApiException
15+
{
16+
}

src/Exceptions/ApiException.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
use Exception;
6+
use GuzzleHttp\Exception\RequestException;
7+
8+
/**
9+
* General Exception
10+
*
11+
* Thrown when the Matrix API returns an HTTP error code that isn't handled by other exceptions
12+
*
13+
* @package Exceptions
14+
* @author Alin Ghitu <[email protected]>
15+
*/
16+
class ApiException extends Exception
17+
{
18+
19+
/**
20+
* @internal
21+
* @param RequestException $e
22+
* @return AccessDeniedException|ApiException|AuthenticationException|ConflictingStateException|
23+
* MethodNotAllowedException|NotFoundException|RateLimitExceededException|UnsupportedAcceptHeaderException|
24+
* UnsupportedContentTypeException|ValidationException
25+
*/
26+
public static function create(RequestException $e) {
27+
28+
if($response = $e->getResponse()) {
29+
switch ($response->getStatusCode()) {
30+
case 400:
31+
return new ValidationException($e);
32+
case 401:
33+
return new AuthenticationException($e);
34+
case 403:
35+
return new AccessDeniedException($e);
36+
case 404:
37+
return new NotFoundException($e);
38+
case 405:
39+
return new MethodNotAllowedException($e);
40+
case 406:
41+
return new UnsupportedAcceptHeaderException($e);
42+
case 409:
43+
return new ConflictingStateException($e);
44+
case 415:
45+
return new UnsupportedContentTypeException($e);
46+
case 429:
47+
return new RateLimitExceededException($e);
48+
}
49+
}
50+
51+
return new ApiException($e);
52+
}
53+
54+
/**
55+
* @var RequestException
56+
* @internal
57+
*/
58+
private $exception;
59+
60+
/**
61+
* Returns the Request Exception
62+
*
63+
* A Guzzle Request Exception is returned
64+
*
65+
* @return RequestException
66+
*/
67+
public function getRequestException()
68+
{
69+
return $this->exception;
70+
}
71+
72+
/**
73+
* Exception constructor
74+
*
75+
* Constructs a new exception.
76+
*
77+
* @param RequestException $e
78+
* @internal
79+
*/
80+
public function __construct(RequestException $e)
81+
{
82+
$this->exception = $e;
83+
parent::__construct();
84+
}
85+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Authentication Exception
7+
*
8+
* Thrown when the Matrix API returns a 401 error,
9+
* which indicates that the Authorization header is either missing or incorrect
10+
*
11+
* @package Exceptions
12+
* @author Alin Ghitu <[email protected]>
13+
*/
14+
class AuthenticationException extends ApiException
15+
{
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Conflicting State Exception
7+
*
8+
* Thrown when the Matrix API returns a 409 code. The resource that is being created/updated is in an inconsistent
9+
* or conflicting state.
10+
*
11+
* @package Exceptions
12+
* @author Alin Ghitu <[email protected]>
13+
*/
14+
class ConflictingStateException extends ApiException
15+
{
16+
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Invalid Configuration Exception
7+
*
8+
* This indicates that the API was not initialized correctly
9+
*
10+
* @package Exceptions
11+
* @author Alin Ghitu <[email protected]>
12+
*/
13+
class InvalidConfigurationException extends \Exception
14+
{
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Method Not Allowed Exception
7+
*
8+
* Thrown when the Matrix API returns a 405 code. This API request used the wrong HTTP verb/method.
9+
*
10+
* @package Exceptions
11+
* @author Alin Ghitu <[email protected]>
12+
*/
13+
class MethodNotAllowedException extends ApiException
14+
{
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Not Found Exception
7+
*
8+
* Thrown when the Matrix API returns a 404 code. This is returned when the request contains an invalid URL.
9+
*
10+
* @package Exceptions
11+
* @author Alin Ghitu <[email protected]>
12+
*/
13+
class NotFoundException extends ApiException
14+
{
15+
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Rate Limit Exceeded
7+
*
8+
* Thrown when a the Matrix API returns a 429 code. The API rate limit alloted for your Matrix domain has been
9+
* exhausted
10+
*
11+
* @package Exceptions
12+
* @author Alin Ghitu <[email protected]>
13+
*/
14+
class RateLimitExceededException extends ApiException
15+
{
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Unsupported Accept Header Exception
7+
*
8+
* Thrown when the Matrix API returns a 406 code. Only application/json and '*\/*' are supported.
9+
* When uploading files multipart/form-data is supported
10+
*
11+
* @package Exceptions
12+
* @author Alin Ghitu <[email protected]>
13+
*/
14+
class UnsupportedAcceptHeaderException extends ApiException
15+
{
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Updivision\Matrix\Exceptions;
4+
5+
/**
6+
* Unsupported Content Type Exception
7+
*
8+
* Thrown when the Matrix API returns a 415 code. Content type application/xml is not supported.
9+
* Only application/json is supported
10+
*
11+
* @package Exceptions
12+
* @author Alin Ghitu <[email protected]>
13+
*/
14+
class UnsupportedContentTypeException extends ApiException
15+
{
16+
17+
}

0 commit comments

Comments
 (0)