diff options
Diffstat (limited to 'Bugzilla/Error.pm')
-rw-r--r-- | Bugzilla/Error.pm | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/Bugzilla/Error.pm b/Bugzilla/Error.pm index 32c7715b4..ef6320d15 100644 --- a/Bugzilla/Error.pm +++ b/Bugzilla/Error.pm @@ -7,8 +7,11 @@ package Bugzilla::Error; +use 5.10.1; use strict; -use base qw(Exporter); +use warnings; + +use parent qw(Exporter); @Bugzilla::Error::EXPORT = qw(ThrowCodeError ThrowTemplateError ThrowUserError); @@ -93,7 +96,7 @@ sub _throw_error { if (Bugzilla->error_mode == ERROR_MODE_WEBPAGE) { my $cgi = Bugzilla->cgi; - $cgi->close_standby_message('text/html', 'inline'); + $cgi->close_standby_message('text/html', 'inline', 'error', 'html'); print $message; print $cgi->multipart_final() if $cgi->{_multipart_in_progress}; } @@ -104,7 +107,8 @@ sub _throw_error { die("$message\n"); } elsif (Bugzilla->error_mode == ERROR_MODE_DIE_SOAP_FAULT - || Bugzilla->error_mode == ERROR_MODE_JSON_RPC) + || Bugzilla->error_mode == ERROR_MODE_JSON_RPC + || Bugzilla->error_mode == ERROR_MODE_REST) { # Clone the hash so we aren't modifying the constant. my %error_map = %{ WS_ERROR_CODE() }; @@ -121,13 +125,20 @@ sub _throw_error { } else { 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, - message => $message, - id => $server->{_bz_request_id}, - version => $server->version); + $server->raise_error(code => 100000 + $code, + status_code => $status_code, + message => $message, + id => $server->{_bz_request_id}, + version => $server->version); # Most JSON-RPC Throw*Error calls happen within an eval inside # of JSON::RPC. So, in that circumstance, instead of exiting, # we die with no message. JSON::RPC checks raise_error before @@ -182,24 +193,18 @@ sub ThrowTemplateError { my $maintainer = Bugzilla->params->{'maintainer'}; my $error = html_quote($vars->{'template_error_msg'}); my $error2 = html_quote($template->error()); + my $url = html_quote(Bugzilla->cgi->self_url); + print <<END; - <tt> <p> Bugzilla has suffered an internal error. Please save this page and send it to $maintainer with details of what you were doing at the time this message appeared. </p> - <script type="text/javascript"> <!-- - document.write("<p>URL: " + - document.location.href.replace(/&/g,"&") - .replace(/</g,"<") - .replace(/>/g,">") + "</p>"); - // --> - </script> + <p>URL: $url</p> <p>Template->process() failed twice.<br> First error: $error<br> Second error: $error2</p> - </tt> END } exit; |