I'm migrating from JSON server, and I think it'd be helpful if you could allow for custom error codes.

Right now the code uses only the codes from the JSON-RPC 2.0 Specification.

Also, it would be great if error messagesinvoked services_error() as well.

If you're interested I can post a patch for 1.x (2.x seems to use Services 3.x, which I haven't looked at).

Thanks,
Mike

Comments

mmilo’s picture

StatusFileSize
new1.12 KB

Anyhow, here's my patch.

- Allows for a custom error code to be returned
- I moved the "name" => 'JSONRPCError' property of the error object to only apply for JSON-RPC 1.1, since it's not required in the 2.0 spec anymore.

mmilo’s picture

StatusFileSize
new1.13 KB

Whoops.

mmilo’s picture

StatusFileSize
new1.62 KB

Included a small change so that error() invokes hook_server_error.

mmilo’s picture

StatusFileSize
new1.16 KB

Re-attaching.

gnugu’s picture

I second that.
I have arrived to the same solution as mmilo. Wanted to post the patch, but it's not needed now :).

Can this be incorporated in the server?

voxpelli’s picture

Status: Active » Needs work

Is custom error codes in compliance with the specification? If not - then this shouldn't be committed unless someone has a very good reason to not follow the specification.

Also: There are a couple of formatting error in the latest patch - use spaces, not tabs. Also - why the switch when there's only one case?

Finally: No review status on this even though it has patches? It should have :) But since there are a few things that should be fixed in the patch I'm moving this to "needs work" instead.

mmilo’s picture

StatusFileSize
new1.09 KB

Rerolled.

Yes, the specification allows for custom error codes. There are error codes reserved for pre-defined errors in the spec - and it's only these error codes the module is currently using.

See http://groups.google.com/group/json-rpc/web/json-rpc-2-0?pli=1.

There's a switch being used only for one case because it's done like that throughout the module, and just in case there is a major version change.