mirror of
https://github.com/predis/predis.git
synced 2026-08-31 12:43:31 +00:00
Change how error messages for server-side errors are handled.
This commit is contained in:
@@ -86,11 +86,11 @@ class PhpiredisConnection extends ConnectionBase {
|
|||||||
private function getErrorHandler($throwErrors = true) {
|
private function getErrorHandler($throwErrors = true) {
|
||||||
if ($throwErrors) {
|
if ($throwErrors) {
|
||||||
return function($errorMessage) {
|
return function($errorMessage) {
|
||||||
throw new ServerException(substr($errorMessage, 4));
|
throw new ServerException($errorMessage);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return function($errorMessage) {
|
return function($errorMessage) {
|
||||||
return new ResponseError(substr($errorMessage, 4));
|
return new ResponseError($errorMessage);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,11 +163,10 @@ class StreamConnection extends ConnectionBase {
|
|||||||
return (int) $payload;
|
return (int) $payload;
|
||||||
|
|
||||||
case '-': // error
|
case '-': // error
|
||||||
$errorMessage = substr($payload, 4);
|
|
||||||
if ($this->_throwErrors) {
|
if ($this->_throwErrors) {
|
||||||
throw new ServerException($errorMessage);
|
throw new ServerException($payload);
|
||||||
}
|
}
|
||||||
return new ResponseError($errorMessage);
|
return new ResponseError($payload);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$this->onProtocolError("Unknown prefix: '$prefix'");
|
$this->onProtocolError("Unknown prefix: '$prefix'");
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ use Predis\Network\IConnectionComposable;
|
|||||||
|
|
||||||
class ResponseErrorHandler implements IResponseHandler {
|
class ResponseErrorHandler implements IResponseHandler {
|
||||||
public function handle(IConnectionComposable $connection, $errorMessage) {
|
public function handle(IConnectionComposable $connection, $errorMessage) {
|
||||||
throw new ServerException(substr($errorMessage, 4));
|
throw new ServerException($errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ use Predis\Network\IConnectionComposable;
|
|||||||
|
|
||||||
class ResponseErrorSilentHandler implements IResponseHandler {
|
class ResponseErrorSilentHandler implements IResponseHandler {
|
||||||
public function handle(IConnectionComposable $connection, $errorMessage) {
|
public function handle(IConnectionComposable $connection, $errorMessage) {
|
||||||
return new ResponseError(substr($errorMessage, 4));
|
return new ResponseError($errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,21 @@ namespace Predis;
|
|||||||
class ResponseError {
|
class ResponseError {
|
||||||
public $skipParse = true;
|
public $skipParse = true;
|
||||||
private $_message;
|
private $_message;
|
||||||
|
private $_type;
|
||||||
|
|
||||||
public function __construct($message) {
|
public function __construct($message) {
|
||||||
$this->_message = $message;
|
$this->_message = $message;
|
||||||
|
$this->_type = substr($message, 0, strpos($message, ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __get($property) {
|
public function __get($property) {
|
||||||
if ($property === 'error') {
|
switch ($property) {
|
||||||
return true;
|
case 'error':
|
||||||
}
|
return true;
|
||||||
if ($property === 'message') {
|
case 'message':
|
||||||
return $this->_message;
|
return $this->_message;
|
||||||
|
case 'type':
|
||||||
|
return $this->_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,18 @@
|
|||||||
namespace Predis;
|
namespace Predis;
|
||||||
|
|
||||||
class ServerException extends PredisException {
|
class ServerException extends PredisException {
|
||||||
// Server-side errors
|
private $_errorType;
|
||||||
|
|
||||||
|
public function __construct($message) {
|
||||||
|
parent::__construct($message);
|
||||||
|
$this->_errorType = substr($message, 0, strpos($message, ' '));
|
||||||
|
}
|
||||||
|
|
||||||
public function toResponseError() {
|
public function toResponseError() {
|
||||||
return new ResponseError($this->getMessage());
|
return new ResponseError($this->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getErrorType() {
|
||||||
|
return $this->_errorType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -25,17 +25,17 @@ class RC {
|
|||||||
const DEFAULT_DATABASE = 15;
|
const DEFAULT_DATABASE = 15;
|
||||||
|
|
||||||
const WIPE_OUT = 1;
|
const WIPE_OUT = 1;
|
||||||
const EXCEPTION_WRONG_TYPE = 'Operation against a key holding the wrong kind of value';
|
const EXCEPTION_WRONG_TYPE = 'ERR Operation against a key holding the wrong kind of value';
|
||||||
const EXCEPTION_NO_SUCH_KEY = 'no such key';
|
const EXCEPTION_NO_SUCH_KEY = 'ERR no such key';
|
||||||
const EXCEPTION_OUT_OF_RANGE = 'index out of range';
|
const EXCEPTION_OUT_OF_RANGE = 'ERR index out of range';
|
||||||
const EXCEPTION_OFFSET_RANGE = 'offset is out of range';
|
const EXCEPTION_OFFSET_RANGE = 'ERR offset is out of range';
|
||||||
const EXCEPTION_INVALID_DB_IDX = 'invalid DB index';
|
const EXCEPTION_INVALID_DB_IDX = 'ERR invalid DB index';
|
||||||
const EXCEPTION_VALUE_NOT_INT = 'value is not an integer';
|
const EXCEPTION_VALUE_NOT_INT = 'ERR value is not an integer';
|
||||||
const EXCEPTION_EXEC_NO_MULTI = 'EXEC without MULTI';
|
const EXCEPTION_EXEC_NO_MULTI = 'ERR EXEC without MULTI';
|
||||||
const EXCEPTION_SETEX_TTL = 'invalid expire time in SETEX';
|
const EXCEPTION_SETEX_TTL = 'ERR invalid expire time in SETEX';
|
||||||
const EXCEPTION_HASH_VALNOTINT = 'hash value is not an integer';
|
const EXCEPTION_HASH_VALNOTINT = 'ERR hash value is not an integer';
|
||||||
const EXCEPTION_BIT_VALUE = 'bit is not an integer or out of range';
|
const EXCEPTION_BIT_VALUE = 'ERR bit is not an integer or out of range';
|
||||||
const EXCEPTION_BIT_OFFSET = 'bit offset is not an integer or out of range';
|
const EXCEPTION_BIT_OFFSET = 'ERR bit offset is not an integer or out of range';
|
||||||
|
|
||||||
private static $_connection;
|
private static $_connection;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user