From dbfd6207290d1eee53fddec4c7c3b4aac0b2d47a Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 8 Apr 2015 18:48:36 +0100 Subject: Bug 1051056: The REST API needs to be versioned so that new changes can be made that do not break compatibility r=dylan,a=glob --- Bugzilla/Error.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Bugzilla/Error.pm') diff --git a/Bugzilla/Error.pm b/Bugzilla/Error.pm index ef6320d15..e730022db 100644 --- a/Bugzilla/Error.pm +++ b/Bugzilla/Error.pm @@ -123,19 +123,13 @@ sub _throw_error { if (Bugzilla->error_mode == ERROR_MODE_DIE_SOAP_FAULT) { die SOAP::Fault->faultcode($code)->faultstring($message); } - else { + elsif (Bugzilla->error_mode == ERROR_MODE_JSON_RPC) { my $server = Bugzilla->_json_server; - my $status_code = 0; - if (Bugzilla->error_mode == ERROR_MODE_REST) { - my %status_code_map = %{ REST_STATUS_CODE_MAP() }; - $status_code = $status_code_map{$code} || $status_code_map{'_default'}; - } # Technically JSON-RPC isn't allowed to have error numbers # higher than 999, but we do this to avoid conflicts with # the internal JSON::RPC error codes. $server->raise_error(code => 100000 + $code, - status_code => $status_code, message => $message, id => $server->{_bz_request_id}, version => $server->version); @@ -146,6 +140,13 @@ sub _throw_error { die if _in_eval(); $server->response($server->error_response_header); } + else { + my $server = Bugzilla->api_server; + my %status_code_map = %{ $server->constants->{REST_STATUS_CODE_MAP} }; + my $status_code = $status_code_map{$code} || $status_code_map{'_default'}; + $server->return_error($status_code, $message, $code); + $server->response; + } } exit; } -- cgit v1.2.3-24-g4f1b