Allow arbitrary error codes in JSON RPC server #5933

Merged
merged 5 commits into from Mar 7, 2014

Conversation

Projects
None yet
2 participants
Contributor

gkralik commented Mar 7, 2014

Currently, the implementation of Zend\Json\Server\Error limits the range of custom error codes from -32000 to -32099. According to the spec (http://www.jsonrpc.org/specification#error_object), this range is "Reserved for implementation-defined server-errors".

The spec continues "The remainder of the space is available for application defined errors". But setting a custom error code (eg 1000) is not allowed by the current implementation and results in the error code being set to -32000.
For a statement of one of the authors of the JSON-RPC specification about usable custom error codes, see this comment.

This PR aims to change the implementation to allow arbitrary error codes.

weierophinney added this to the 2.3.0 milestone Mar 7, 2014

weierophinney self-assigned this Mar 7, 2014

Owner

weierophinney commented Mar 7, 2014

This introduces a new error in ZendTest\Json\ServerTest::testHandleRequestWithExceptionShouldReturnErrorResponse - "Failed asserting that 0 matches expected -32000." Can you review, please?

Contributor

gkralik commented Mar 7, 2014

Looks like the test asset throws an exception without setting a code. This results in the code being 0 (zero), but the test expects it to be -32000. This is a problem. Maybe we should handle this by checking for a zero code in Error:setCode and converting 0 to -32000. So everytime the user does not explicitly set an error code, it would default to -32000

Owner

weierophinney commented Mar 7, 2014

@gkralik sounds good! Make it so! :)

@gkralik gkralik 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.
9c9fe49
Contributor

gkralik commented Mar 7, 2014

Done. Tests seems to be passing now.

@weierophinney weierophinney added a commit that referenced this pull request Mar 7, 2014

@weierophinney weierophinney [#5933] CS fixes
- braces
0a9d843

@weierophinney weierophinney added a commit that referenced this pull request Mar 7, 2014

@weierophinney weierophinney Merge branch 'feature/5933' into develop
Close #5933
8ee3591

weierophinney merged commit 9c9fe49 into zendframework:develop Mar 7, 2014

gkralik deleted the unknown repository branch Mar 7, 2014

@weierophinney weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge pull request zendframework/zendframework#5933 from gkralik/fix/…
…json-rpc-error-codes

Allow arbitrary error codes in JSON RPC server
cc6e408

@weierophinney weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge pull request zendframework/zendframework#5933 from gkralik/fix/…
…json-rpc-error-codes

Allow arbitrary error codes in JSON RPC server
1847405

@weierophinney weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015

@weierophinney weierophinney [zendframework/zendframework#5933] CS fixes
- braces
0d167fb

@weierophinney weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015

@weierophinney weierophinney [zendframework/zendframework#5933] Use dataProvider for new test cbb433a

@weierophinney weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge branch 'feature/5933' into develop a58cddc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment