diff options
author | David Lawrence <dkl@mozilla.com> | 2014-11-11 04:17:10 +0100 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2014-11-11 04:17:10 +0100 |
commit | 2d223dcbe7bf5c045a11ea489a0964129518731e (patch) | |
tree | 28c45230ef0b80f5d4f8d5f4a0dc414a89a72f8e | |
parent | c2533c1f2e7c5c4376eb0dae17c3380b04067678 (diff) | |
download | bugzilla-2d223dcbe7bf5c045a11ea489a0964129518731e.tar.gz bugzilla-2d223dcbe7bf5c045a11ea489a0964129518731e.tar.xz |
Bug 1089805: BzAPI compatibility layer returns HTTP 200 when a bug update failed
-rw-r--r-- | Bugzilla/Hook.pm | 20 | ||||
-rw-r--r-- | Bugzilla/WebService/Constants.pm | 47 | ||||
-rw-r--r-- | extensions/BzAPI/Extension.pm | 7 | ||||
-rw-r--r-- | extensions/Example/Extension.pm | 12 |
4 files changed, 65 insertions, 21 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index fff102232..942623dcf 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -1701,6 +1701,26 @@ The current JSONRPC, XMLRPC, or REST object. =back +=head2 wevservice_status_code_map + +This hook allows an extension to change the status codes returned by +specific webservice errors. The valid internal error codes that Bugzilla +generates, and the status codes they map to by default, are defined in the +C<WS_ERROR_CODE> constant in C<Bugzilla::WebService::Constants>. When +remapping an error, you may wish to use an existing status code constant. +Such constants are also in C<Bugzilla::WebService::Constants> and start +with C<STATUS_*> such as C<STATUS_BAD_REQUEST>. + +Params: + +=over + +=item C<status_code_map> + +A hash reference containing the current status code mapping. + +=back + =head1 SEE ALSO L<Bugzilla::Extension> diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index 72863cb0f..83cae251b 100644 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -225,26 +225,33 @@ use constant STATUS_GONE => 410; # the related webvservice call. We choose the appropriate # http status code based on the error code or use the # default STATUS_BAD_REQUEST. -use constant REST_STATUS_CODE_MAP => { - 51 => STATUS_NOT_FOUND, - 101 => STATUS_NOT_FOUND, - 102 => STATUS_NOT_AUTHORIZED, - 106 => STATUS_NOT_AUTHORIZED, - 109 => STATUS_NOT_AUTHORIZED, - 110 => STATUS_NOT_AUTHORIZED, - 113 => STATUS_NOT_AUTHORIZED, - 115 => STATUS_NOT_AUTHORIZED, - 120 => STATUS_NOT_AUTHORIZED, - 300 => STATUS_NOT_AUTHORIZED, - 301 => STATUS_NOT_AUTHORIZED, - 302 => STATUS_NOT_AUTHORIZED, - 303 => STATUS_NOT_AUTHORIZED, - 304 => STATUS_NOT_AUTHORIZED, - 410 => STATUS_NOT_AUTHORIZED, - 504 => STATUS_NOT_AUTHORIZED, - 505 => STATUS_NOT_AUTHORIZED, - 32614 => STATUS_NOT_FOUND, - _default => STATUS_BAD_REQUEST +sub REST_STATUS_CODE_MAP { + my $status_code_map = { + 51 => STATUS_NOT_FOUND, + 101 => STATUS_NOT_FOUND, + 102 => STATUS_NOT_AUTHORIZED, + 106 => STATUS_NOT_AUTHORIZED, + 109 => STATUS_NOT_AUTHORIZED, + 110 => STATUS_NOT_AUTHORIZED, + 113 => STATUS_NOT_AUTHORIZED, + 115 => STATUS_NOT_AUTHORIZED, + 120 => STATUS_NOT_AUTHORIZED, + 300 => STATUS_NOT_AUTHORIZED, + 301 => STATUS_NOT_AUTHORIZED, + 302 => STATUS_NOT_AUTHORIZED, + 303 => STATUS_NOT_AUTHORIZED, + 304 => STATUS_NOT_AUTHORIZED, + 410 => STATUS_NOT_AUTHORIZED, + 504 => STATUS_NOT_AUTHORIZED, + 505 => STATUS_NOT_AUTHORIZED, + 32614 => STATUS_NOT_FOUND, + _default => STATUS_BAD_REQUEST + }; + + Bugzilla::Hook::process('webservice_status_code_map', + { status_code_map => $status_code_map }); + + return $status_code_map; }; # These are the fallback defaults for errors not in ERROR_CODE. diff --git a/extensions/BzAPI/Extension.pm b/extensions/BzAPI/Extension.pm index cd08369b0..e6159243a 100644 --- a/extensions/BzAPI/Extension.pm +++ b/extensions/BzAPI/Extension.pm @@ -17,6 +17,7 @@ use Bugzilla::Error; use Bugzilla::Util qw(trick_taint datetime_from); use Bugzilla::Constants; use Bugzilla::Install::Filesystem; +use Bugzilla::WebService::Constants; use File::Basename; @@ -169,6 +170,12 @@ sub webservice_rest_resources { _add_resources($rpc, $resources); } +sub webservice_status_code_map { + my ($self, $args) = @_; + my $status_code_map = $args->{status_code_map}; + $status_code_map->{51} = STATUS_BAD_REQUEST; +} + ##################### # Utility Functions # ##################### diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index a42f87b9e..5b76935e3 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -32,6 +32,7 @@ use Bugzilla::User::Setting; use Bugzilla::Util qw(diff_arrays html_quote); use Bugzilla::Status qw(is_open_state); use Bugzilla::Install::Filesystem; +use Bugzilla::WebService::Constants; # This is extensions/Example/lib/Util.pm. I can load this here in my # Extension.pm only because I have a Config.pm. @@ -950,11 +951,20 @@ sub webservice { sub webservice_error_codes { my ($self, $args) = @_; - + my $error_map = $args->{error_map}; $error_map->{'example_my_error'} = 10001; } +sub webservice_status_code_map { + my ($self, $args) = @_; + + my $status_code_map = $args->{status_code_map}; + # Uncomment this line to override the status code for the + # error 'object_does_not_exist' to STATUS_BAD_REQUEST + #$status_code_map->{51} = STATUS_BAD_REQUEST; +} + sub webservice_before_call { my ($self, $args) = @_; |