Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5933 from gkralik/fix/…
Browse files Browse the repository at this point in the history
…json-rpc-error-codes

Allow arbitrary error codes in JSON RPC server
  • Loading branch information
weierophinney committed Mar 7, 2014
2 parents cc6e408 + f2b3e09 commit 1847405
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Server/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 1847405

Please sign in to comment.