summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-02-23 01:11:00 +0100
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-02-23 01:11:00 +0100
commit2f34ebff96ec03af7aa06074f706b8a696f6cd36 (patch)
treea383c7c90b749d2d7aec035fd33029c27c95cee1 /Bugzilla
parentc893bcf568f8e48a68e968299be7a9fc946f7226 (diff)
downloadbugzilla-2f34ebff96ec03af7aa06074f706b8a696f6cd36.tar.gz
bugzilla-2f34ebff96ec03af7aa06074f706b8a696f6cd36.tar.xz
Bug 547126: Make the JSON-RPC return error codes that are numerically
identical to the XML-RPC error codes. r=dkl, a=mkanat
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/WebService/Server/JSONRPC.pm57
1 files changed, 52 insertions, 5 deletions
diff --git a/Bugzilla/WebService/Server/JSONRPC.pm b/Bugzilla/WebService/Server/JSONRPC.pm
index d6af25043..cc3e8058e 100644
--- a/Bugzilla/WebService/Server/JSONRPC.pm
+++ b/Bugzilla/WebService/Server/JSONRPC.pm
@@ -85,6 +85,43 @@ sub datetime_format {
return $iso_datetime;
}
+# Make all error messages returned by JSON::RPC go into the 100000
+# range, and bring down all our errors into the normal range.
+sub _error {
+ my ($self, $id, $code) = (shift, shift, shift);
+ # All JSON::RPC errors are less than 1000.
+ if ($code < 1000) {
+ $code += 100000;
+ }
+ # Bugzilla::Error adds 100,000 to all *our* errors, so
+ # we know they came from us.
+ elsif ($code > 100000) {
+ $code -= 100000;
+ }
+
+ # We can't just set $_[1] because it's not always settable,
+ # in JSON::RPC::Server.
+ unshift(@_, $id, $code);
+ my $json = $self->SUPER::_error(@_);
+
+ # We want to always send the JSON-RPC 1.1 error format, although
+ # If we're not in JSON-RPC 1.1, we don't need the silly "name" parameter.
+ if (!$self->version) {
+ my $object = $self->json->decode($json);
+ my $message = $object->{error};
+ # Just assure that future versions of JSON::RPC don't change the
+ # JSON-RPC 1.0 error format.
+ if (!ref $message) {
+ $object->{error} = {
+ code => $code,
+ message => $message,
+ };
+ $json = $self->json->encode($object);
+ }
+ }
+ return $json;
+}
+
##################
# Login Handling #
##################
@@ -254,12 +291,22 @@ All other types are standard JSON types.
=head1 ERRORS
-All errors thrown by Bugzilla itself have 100000 added to their numeric
-code. So, if the documentation says that an error is C<302>, then
-it will be C<100302> when it is thrown via JSON-RPC.
+JSON-RPC 1.0 and JSON-RPC 1.1 both return an C<error> element when they
+throw an error. In Bugzilla, the error contents look like:
+
+ { message: 'Some message here', code: 123 }
+
+So, for example, in JSON-RPC 1.0, an error response would look like:
+
+ {
+ result: null,
+ error: { message: 'Some message here', code: 123 },
+ id: 1
+ }
-Errors less than 100000 are errors thrown by the JSON-RPC library that
-Bugzilla uses, not by Bugzilla.
+Every error has a "code", as described in L<Bugzilla::WebService/ERRORS>.
+Errors with a numeric C<code> higher than 100000 are errors thrown by
+the JSON-RPC library that Bugzilla uses, not by Bugzilla.
=head1 SEE ALSO