aboutsummaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@mozilla.com>2014-11-10 16:08:13 +0000
committerDavid Lawrence <dkl@mozilla.com>2014-11-10 16:10:06 +0000
commit4e5a3b1633b0f75611da16d2520a3fc27d15673e (patch)
tree847f59881ff2cd1ff8431bf1a07c8d13a3b332f6 /Bugzilla
parent0d7b9c62b132c945114de061eb3d783fd4344e0e (diff)
downloadbugs-4e5a3b1633b0f75611da16d2520a3fc27d15673e.tar
bugs-4e5a3b1633b0f75611da16d2520a3fc27d15673e.tar.gz
bugs-4e5a3b1633b0f75611da16d2520a3fc27d15673e.tar.bz2
bugs-4e5a3b1633b0f75611da16d2520a3fc27d15673e.tar.xz
bugs-4e5a3b1633b0f75611da16d2520a3fc27d15673e.zip
Bug 1094858: Create hook in Bugzilla::WebService::Constants to allow overrriding of standard status codes by extensions
r=gerv,a=glob
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Hook.pm20
-rw-r--r--Bugzilla/WebService/Constants.pm48
2 files changed, 48 insertions, 20 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index 2904acba1..430d5af49 100644
--- a/Bugzilla/Hook.pm
+++ b/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<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 d612ebc75..503b91bbb 100644
--- a/Bugzilla/WebService/Constants.pm
+++ b/Bugzilla/WebService/Constants.pm
@@ -238,26 +238,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.
@@ -306,6 +313,7 @@ sub WS_DISPATCH {
=over
+=item REST_STATUS_CODE_MAP
=item WS_DISPATCH
=back