Fix error message in case of server error
Change-Id: I72528fea917f91d16b3fee8cb4c47282b9b08556
diff --git a/Changes b/Changes
index 6c0a899..d60a2ff 100755
--- a/Changes
+++ b/Changes
@@ -1,7 +1,9 @@
-0.43 2021-06-29
+0.43 2021-07-02
- New menu class that has an entry at the very end,
similar to the input text prefix,
that is always available (lerepp).
+ - Fix error message in case of server error (500)
+ response.
0.42 2021-06-18
- Added GitHub based CI for perl.
diff --git a/lib/Kalamar/Plugin/Auth.pm b/lib/Kalamar/Plugin/Auth.pm
index db9728d..df6302d 100644
--- a/lib/Kalamar/Plugin/Auth.pm
+++ b/lib/Kalamar/Plugin/Auth.pm
@@ -70,6 +70,7 @@
tokenInvalid => 'Zugriffstoken ungültig',
refreshFail => 'Fehlerhafter Refresh-Token',
responseError => 'Unbekannter Autorisierungsfehler',
+ serverError => 'Unbekannter Serverfehler',
revokeFail => 'Der Token kann nicht widerrufen werden',
revokeSuccess => 'Der Token wurde erfolgreich widerrufen',
paramError => 'Einige Eingaben sind fehlerhaft',
@@ -115,6 +116,7 @@
tokenInvalid => 'Access token invalid',
refreshFail => 'Bad refresh token',
responseError => 'Unknown authorization error',
+ serverError => 'Unknown server error',
revokeFail => 'Token can\'t be revoked',
revokeSuccess => 'Token was revoked successfully',
paramError => 'Some fields are invalid',
@@ -341,6 +343,12 @@
);
};
+ if ($tx->res->is_server_error) {
+ return Mojo::Promise->reject(
+ '600'
+ )
+ };
+
$c->notify(error => $c->loc('Auth_responseError'));
return Mojo::Promise->reject;
}
@@ -567,6 +575,18 @@
};
return Mojo::Promise->resolve($tx);
+ }
+
+ # There is a server error - just report
+ elsif ($tx->res->is_server_error) {
+ my $err = $tx->res->error;
+ if ($err) {
+ return Mojo::Promise->reject($err->{code} . ': ' . $err->{message});
+ }
+ else {
+ $c->notify(error => $c->loc('Auth_serverError'));
+ return Mojo::Promise->reject;
+ };
};
$c->notify(error => $c->loc('Auth_responseError'));
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 7db935f..33ffafa 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -236,6 +236,11 @@
->element_exists_not('p.hint')
;
+# Query with error
+$t->get_ok('/?q=error')
+ ->status_is(400)
+ ->text_is('#notifications .notify-error','500: Internal Server Error')
+;
# Logout
$t->get_ok('/user/logout')
diff --git a/t/query.t b/t/query.t
index d3f0cd3..50d81b1 100644
--- a/t/query.t
+++ b/t/query.t
@@ -225,6 +225,12 @@
->text_is('#total-results', '> 4,274,841');
;
+# Query with error
+$t->get_ok('/?q=error')
+ ->status_is(400)
+ ->text_is('#notifications .notify-error','500: Internal Server Error')
+;
+
# Do not cache
$t->get_ok('/?q=timeout')
->status_is(200)
diff --git a/t/server/mock.pl b/t/server/mock.pl
index bd6debe..5389156 100644
--- a/t/server/mock.pl
+++ b/t/server/mock.pl
@@ -150,6 +150,13 @@
return $c->render(%{$c->load_response('query_no_query')});
};
+ if ($v->param('q') eq 'error') {
+ return $c->render(
+ status => 500,
+ inline => '<html><head>ERROR</head></html>'
+ );
+ };
+
my @slug_base = ($v->param('q'));
push @slug_base, 'o' . $v->param('offset') if defined $v->param('offset');
push @slug_base, 'c' . $v->param('count') if defined $v->param('count');