Adding exceptions

This commit is contained in:
Yoann Celton 2018-11-27 22:40:33 +11:00 committed by Aryess
parent 4d6463d034
commit 4d64c6bce5
4 changed files with 86 additions and 0 deletions

View 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 {}

View 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);
}
}

View 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;
}
}

View 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;
}
}