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

Allow arbitrary error codes in JSON RPC server #5933

Merged
merged 5 commits into from
Mar 7, 2014
Merged

Allow arbitrary error codes in JSON RPC server #5933

merged 5 commits into from
Mar 7, 2014

Conversation

gkralik
Copy link
Contributor

@gkralik 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.

Gregor Kralik added 4 commits March 7, 2014 21:25
@weierophinney weierophinney added this to the 2.3.0 milestone Mar 7, 2014
@weierophinney weierophinney self-assigned this Mar 7, 2014
@weierophinney
Copy link
Member

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

@gkralik
Copy link
Contributor Author

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

@weierophinney
Copy link
Member

@gkralik sounds good! Make it so! :)

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.
@gkralik
Copy link
Contributor Author

gkralik commented Mar 7, 2014

Done. Tests seems to be passing now.

weierophinney added a commit that referenced this pull request Mar 7, 2014
Allow arbitrary error codes in JSON RPC server
weierophinney added a commit that referenced this pull request Mar 7, 2014
Allow arbitrary error codes in JSON RPC server
weierophinney added a commit that referenced this pull request Mar 7, 2014
weierophinney added a commit that referenced this pull request Mar 7, 2014
weierophinney added a commit that referenced this pull request Mar 7, 2014
@weierophinney weierophinney merged commit 9c9fe49 into zendframework:develop Mar 7, 2014
@gkralik gkralik deleted the fix/json-rpc-error-codes branch March 7, 2014 21:37
weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015
…json-rpc-error-codes

Allow arbitrary error codes in JSON RPC server
weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015
…json-rpc-error-codes

Allow arbitrary error codes in JSON RPC server
weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-json that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants