Bug 1094858: Create hook in Bugzilla::WebService::Constants to allow overrriding of standard status codes by extensions
r=gerv,a=glob git-svn-id: svn://10.0.0.236/trunk@265667 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
4ef0207a07
commit
fe358a8183
@ -1 +1 @@
|
||||
9202
|
||||
9203
|
||||
@ -1 +1 @@
|
||||
41dbccc20f013f0b06959ad587f5fb6ac4813686
|
||||
b9543e48f33729c4a4560eac2a856af06ed9e9d5
|
||||
@ -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>
|
||||
|
||||
@ -239,7 +239,8 @@ 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 => {
|
||||
sub REST_STATUS_CODE_MAP {
|
||||
my $status_code_map = {
|
||||
51 => STATUS_NOT_FOUND,
|
||||
101 => STATUS_NOT_FOUND,
|
||||
102 => STATUS_NOT_AUTHORIZED,
|
||||
@ -261,6 +262,12 @@ use constant REST_STATUS_CODE_MAP => {
|
||||
_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.
|
||||
use constant ERROR_UNKNOWN_FATAL => -32000;
|
||||
use constant ERROR_UNKNOWN_TRANSIENT => 32000;
|
||||
@ -307,6 +314,7 @@ sub WS_DISPATCH {
|
||||
|
||||
=over
|
||||
|
||||
=item REST_STATUS_CODE_MAP
|
||||
=item WS_DISPATCH
|
||||
|
||||
=back
|
||||
|
||||
@ -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.
|
||||
@ -963,6 +964,15 @@ sub webservice_error_codes {
|
||||
$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) = @_;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user