diff --git a/mozilla/webtools/bugzilla/.bzrrev b/mozilla/webtools/bugzilla/.bzrrev index 9fa1257d54c..6a28ed836d5 100644 --- a/mozilla/webtools/bugzilla/.bzrrev +++ b/mozilla/webtools/bugzilla/.bzrrev @@ -1 +1 @@ -9202 \ No newline at end of file +9203 \ No newline at end of file diff --git a/mozilla/webtools/bugzilla/.gitrev b/mozilla/webtools/bugzilla/.gitrev index bfeb937dd32..e793cf022c8 100644 --- a/mozilla/webtools/bugzilla/.gitrev +++ b/mozilla/webtools/bugzilla/.gitrev @@ -1 +1 @@ -41dbccc20f013f0b06959ad587f5fb6ac4813686 \ No newline at end of file +b9543e48f33729c4a4560eac2a856af06ed9e9d5 \ No newline at end of file diff --git a/mozilla/webtools/bugzilla/Bugzilla/Hook.pm b/mozilla/webtools/bugzilla/Bugzilla/Hook.pm index 2904acba143..430d5af49a6 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Hook.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Hook.pm @@ -1704,6 +1704,26 @@ The current JSONRPC, XMLRPC, or REST object. =back +=head2 webservice_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 constant in C. When +remapping an error, you may wish to use an existing status code constant. +Such constants are also in C and start +with C such as C. + +Params: + +=over + +=item C + +A hash reference containing the current status code mapping. + +=back + =head1 SEE ALSO L diff --git a/mozilla/webtools/bugzilla/Bugzilla/WebService/Constants.pm b/mozilla/webtools/bugzilla/Bugzilla/WebService/Constants.pm index db50611cbf6..2f38c8db148 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/WebService/Constants.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/WebService/Constants.pm @@ -239,26 +239,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. @@ -307,6 +314,7 @@ sub WS_DISPATCH { =over +=item REST_STATUS_CODE_MAP =item WS_DISPATCH =back diff --git a/mozilla/webtools/bugzilla/extensions/Example/Extension.pm b/mozilla/webtools/bugzilla/extensions/Example/Extension.pm index 256589dab08..af36b107af6 100644 --- a/mozilla/webtools/bugzilla/extensions/Example/Extension.pm +++ b/mozilla/webtools/bugzilla/extensions/Example/Extension.pm @@ -21,6 +21,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. @@ -958,11 +959,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) = @_;