Permalink
Browse files

fix failing testHandleRequestWithExceptionShouldReturnErrorResponse

if an Exception is thrown without setting a code manually, it defaults to 0. change Error:setCode to set the code to -32000 (ERROR_OTHER) if this is the case.
  • Loading branch information...
1 parent 76da2f8 commit 9c9fe49b0523c7ec1803d1165a0e89e46ff27d5d @gkralik gkralik committed Mar 7, 2014
Showing with 11 additions and 4 deletions.
  1. +11 −4 library/Zend/Json/Server/Error.php
@@ -45,12 +45,14 @@ class Error
*/
public function __construct($message = null, $code = self::ERROR_OTHER, $data = null) {
$this->setMessage($message)
- ->setCode($code)
- ->setData($data);
+ ->setCode($code)
+ ->setData($data);
}
/**
- * Set error code
+ * Set error code.
+ *
+ * If the error code is 0, it will be set to -32000 (ERROR_OTHER).
*
* @param int $code
* @return \Zend\Json\Server\Error
@@ -66,7 +68,12 @@ public function setCode($code)
}
$code = (int) $code;
- $this->code = $code;
+
+ if (0 === $code) {
+ $this->code = self::ERROR_OTHER;
+ } else {
+ $this->code = $code;
+ }
return $this;
}

0 comments on commit 9c9fe49

Please sign in to comment.