aces / cbrain

CBRAIN is a flexible Ruby on Rails framework for accessing and processing of large data on high-performance computing infrastructures.
GNU General Public License v3.0
71 stars 42 forks source link

Trying to upload a file that already exists shows bad error message #1309

Open prioux opened 1 year ago

prioux commented 1 year ago

When trying to upload a file that already exists, users get to see the message "422 Unprocessable entity"; that show up until a new page is loaded and THEN the proper message "name has already been taken" is shown.

MontrealSergiy commented 1 year ago

more like not user-friendly than totally bad.

The message is created by the Generic AJAX error handler line 28 cbrain.js.

MontrealSergiy commented 1 year ago

Click on Upload creates a json request rather than redirect in controller, then json response intercepted by 'generic ajax error handler' at line 28 of cbrain.js

Adding JSON response handler, which checks for notices could help (currently only XML content is addressed, though I thought we seldom use XML). It might though create error message duplication . May be ignoring json error responses with notices better, not sure.

I meant something akin

    --- a/BrainPortal/public/javascripts/cbrain.js
+++ b/BrainPortal/public/javascripts/cbrain.js
@@ -28,10 +28,10 @@
   /* Generic AJAX error handler */
   $(document).ajaxError(function (event, xhr, settings, error) {
     var flash = $('.flash_error'),
-        xml   = $(xhr.responseXML);
-
+        xml   = $(xhr.responseXML),
+        rjson  = xhr.responseJSON;
     if (xhr.status === 0) return true;

     if (!flash.length)
       flash = $('<div class="flash_error">')
         .prependTo('#main');
@@ -44,6 +44,8 @@
           .get()
           .join('<br />')
       );
+    else if (rjson && rjson.notice && rjson.notice)
+      flash.html(rjson.notice)
     else
       flash.html(
         'Error sending background request: <br />' +
prioux commented 1 year ago

If you have a solution, make a PR...