Adding exceptions
This commit is contained in:
parent
4d6463d034
commit
4d64c6bce5
10
src/Exceptions/MatrixException.php
Normal file
10
src/Exceptions/MatrixException.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Aryess\PhpMatrixSdk\Exceptions;
|
||||
|
||||
/**
|
||||
* A generic Matrix error. Specific errors will subclass this.
|
||||
*
|
||||
* @package Aryess\PhpMatrixSdk\Exceptions
|
||||
*/
|
||||
abstract class MatrixException extends \Exception {}
|
17
src/Exceptions/MatrixHttpLibException.php
Normal file
17
src/Exceptions/MatrixHttpLibException.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Aryess\PhpMatrixSdk\Exceptions;
|
||||
|
||||
/**
|
||||
* The library used for http requests raised an exception.
|
||||
*
|
||||
* @package Aryess\PhpMatrixSdk\Exceptions
|
||||
*/
|
||||
class MatrixHttpLibException extends MatrixException {
|
||||
|
||||
public function __construct(\Exception $originalException, string $method, string $endpoint) {
|
||||
$msg = "Something went wrong in %s requesting %s: %s";
|
||||
$msg = sprintf($msg, $method, $endpoint, $originalException);
|
||||
parent::__construct($msg);
|
||||
}
|
||||
}
|
34
src/Exceptions/MatrixRequestException.php
Normal file
34
src/Exceptions/MatrixRequestException.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Aryess\PhpMatrixSdk\Exceptions;
|
||||
|
||||
/**
|
||||
* The home server returned an error response.
|
||||
*
|
||||
* @package Aryess\PhpMatrixSdk\Exceptions
|
||||
*/
|
||||
class MatrixRequestException extends MatrixException {
|
||||
|
||||
protected $httpCode;
|
||||
protected $content;
|
||||
|
||||
public function __construct(int $code = 0, string $content = "") {
|
||||
parent::__construct("$code: $content");
|
||||
$this->httpCode = $code;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHttpCode(): int {
|
||||
return $this->httpCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(): string {
|
||||
return $this->content;
|
||||
}
|
||||
}
|
25
src/Exceptions/MatrixUnexpectedResponse.php
Normal file
25
src/Exceptions/MatrixUnexpectedResponse.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Aryess\PhpMatrixSdk\Exceptions;
|
||||
|
||||
/**
|
||||
* The home server gave an unexpected response.
|
||||
*
|
||||
* @package Aryess\PhpMatrixSdk\Exceptions
|
||||
*/
|
||||
class MatrixUnexpectedResponse extends MatrixException {
|
||||
|
||||
protected $content;
|
||||
|
||||
function __construct(string $content = '') {
|
||||
parent::__construct($content);
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(): string {
|
||||
return $this->content;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue