Bug 23075: Better error handling in Mana config
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 8 Jun 2019 18:57:05 +0000 (13:57 -0500)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Sat, 15 Jun 2019 06:51:30 +0000 (07:51 +0100)
Currently, if you input an incorrect mana service URL in your config
(http rather than https for example) the error message you are given is
the direct output of a failed json parse.  We should be able to catch
such failures and display a more meaningful error to the end user.

This patch makes it display a more friendly message.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/SharedContent.pm
koha-tmpl/intranet-tmpl/prog/en/modules/admin/share_content.tt

index 7145e95..d2129d9 100644 (file)
@@ -52,6 +52,13 @@ sub process_request {
 
     my $response = $userAgent->request($mana_request);
 
+    if ( $response->code != 200 ) {
+        return {
+            code => $response->code,
+            msg  => $response->message,
+        };
+    }
+
     eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); };
     $result->{code} = $response->code;
     if ( $@ ){
index 11d4e6c..df8599e 100644 (file)
@@ -19,7 +19,7 @@
             <div class="col-sm-6">
                 [% IF result.code != 201 && result.msg %]
                     <div class="dialog alert" role="alert">
-                        [% result.msg | html %]
+                        Error trying to connect or read response from the Mana server (Code: [% result.code | html %]) [% result.msg | html %]
                     </div>
                 [% END %]