-
Notifications
You must be signed in to change notification settings - Fork 203
Bug 1675625 - Refactor error handing in Mojolicious to allow for native mojo code to something other than Bugzilla::Error #1655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
c05319a
Bump version to 20200117.1
dklawren f66659c
Merge remote-tracking branch 'upstream/master'
dklawren 1457930
Merge remote-tracking branch 'upstream/master'
dklawren 879c02a
Merge remote-tracking branch 'upstream/master'
dklawren cf08e61
Merge remote-tracking branch 'upstream/master'
dklawren 9c9e237
Merge remote-tracking branch 'upstream/master'
dklawren 0d8cb41
Merge remote-tracking branch 'upstream/master'
dklawren c48e749
Merge remote-tracking branch 'upstream/master'
dklawren 44f1149
Merge remote-tracking branch 'upstream/master'
dklawren db980c8
Merge remote-tracking branch 'upstream/master'
dklawren 9bce0ae
Merge remote-tracking branch 'upstream/master'
dklawren f8194dc
Merge remote-tracking branch 'upstream/master'
f5e8ed5
Merge remote-tracking branch 'upstream/master'
dklawren be21ec1
Merge branch 'master' of https://github.com/dklawren/bmo
dklawren 698f56f
Merge remote-tracking branch 'upstream/master'
dklawren d96a196
Merge remote-tracking branch 'upstream/master'
dklawren a4ccc14
Merge remote-tracking branch 'upstream/master'
dklawren e83671b
Merge remote-tracking branch 'upstream/master'
dklawren 52fd38a
Merge remote-tracking branch 'upstream/master'
dklawren 4175907
Merge remote-tracking branch 'upstream/master'
dklawren 32293eb
Merge remote-tracking branch 'upstream/master'
dklawren b332a70
Merge remote-tracking branch 'upstream/master'
dklawren 61b5a62
Merge remote-tracking branch 'upstream/master'
dklawren 3310020
Merge remote-tracking branch 'upstream/master'
dklawren 1089d75
Merge remote-tracking branch 'upstream/master'
dklawren a2a2e82
Merge remote-tracking branch 'upstream/master'
dklawren 00d6e6a
Merge remote-tracking branch 'upstream/master'
dklawren 2adfd4c
Merge remote-tracking branch 'upstream/master'
dklawren 96b7356
Merge remote-tracking branch 'upstream/master' into master
dklawren bb3076f
Merge remote-tracking branch 'upstream/master'
dklawren e1b2175
Merge remote-tracking branch 'upstream/master'
dklawren 2000ac8
Merge remote-tracking branch 'upstream/master'
dklawren 27acdda
Merge remote-tracking branch 'upstream/master'
dklawren 5bf03d7
Merge remote-tracking branch 'upstream/master'
dklawren 561592d
Bug 1675625 - Refactor error handing in Mojolicious to allow for nati…
dklawren 621632f
- Fixed an issue with oauth2 clients and selecting multiple scopes
dklawren 4a5d168
- Refactoring to allow setting USAGE_MODE_REST for API error reporting
dklawren e809da4
Merge remote-tracking branch 'upstream/master' into master
dklawren 2c42f09
Merge branch 'mojo-error-handling' of https://github.com/dklawren/bmo…
dklawren 79a6ca6
Update base on review comments.
dklawren 7ae1d0c
Merge branch 'master' into mojo-error-handling
dklawren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| package Bugzilla::App::Plugin::Error; | ||
| use 5.10.1; | ||
| use Mojo::Base 'Mojolicious::Plugin'; | ||
|
|
||
| use Bugzilla::Constants; | ||
| use Bugzilla::Logging; | ||
| use Bugzilla::WebService::Constants; | ||
|
|
||
| sub register { | ||
| my ($self, $app) = @_; | ||
| $app->helper('code_error' => sub { _render_error('code', @_); }); | ||
| $app->helper('user_error' => sub { _render_error('user', @_); }); | ||
| } | ||
|
|
||
| sub _render_error { | ||
| my ($type, $c, $error, $vars) = @_; | ||
| my $logfunc = _make_logfunc(ucfirst($type)); | ||
|
|
||
| # Errors displayed in a web page | ||
| if (Bugzilla->error_mode == ERROR_MODE_MOJO | ||
| || Bugzilla->error_mode == ERROR_MODE_WEBPAGE) | ||
| { | ||
| $logfunc->("webpage error: $error"); | ||
|
|
||
| $c->render( | ||
| handler => 'bugzilla', | ||
| template => "global/$type-error", | ||
| format => 'html', | ||
| error => $error, | ||
| %{$vars} | ||
| ); | ||
| } | ||
|
|
||
| # Errors returned in an API request | ||
| elsif (Bugzilla->error_mode == ERROR_MODE_REST) { | ||
| my %error_map = %{WS_ERROR_CODE()}; | ||
| my $code = $error_map{$error}; | ||
|
|
||
| if (!$code) { | ||
| $code = ERROR_UNKNOWN_FATAL if $type =~ /code/i; | ||
| $code = ERROR_UNKNOWN_TRANSIENT if $type =~ /user/i; | ||
| } | ||
|
|
||
| my %status_code_map = %{REST_STATUS_CODE_MAP()}; | ||
| my $status_code = $status_code_map{$code} || $status_code_map{'_default'}; | ||
|
|
||
| $logfunc->("REST error: $error (HTTP $status_code, internal code $code)"); | ||
|
|
||
| # Find the full error message | ||
| my $message; | ||
| $vars->{error} = $error; | ||
| my $template = Bugzilla->template; | ||
| $template->process("global/$type-error.html.tmpl", $vars, \$message) | ||
| || die $template->error(); | ||
|
|
||
| my $error = { | ||
| error => 1, | ||
| code => $code, | ||
| message => $message, | ||
| documentation => 'https://bmo.readthedocs.io/en/latest/api/', | ||
| }; | ||
|
|
||
| $c->render(json => $error, status => $status_code); | ||
| } | ||
| } | ||
|
|
||
| sub _make_logfunc { | ||
| my ($type) = @_; | ||
| my $logger = Log::Log4perl->get_logger("Bugzilla.Error.$type"); | ||
| return sub { | ||
| local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 3; | ||
| if ($type eq 'User') { | ||
| $logger->warn(@_); | ||
| } | ||
| else { | ||
| $logger->error(@_); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.