Commit 2f34ebff authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

Bug 547126: Make the JSON-RPC return error codes that are numerically

identical to the XML-RPC error codes. r=dkl, a=mkanat
parent c893bcf5
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment