Skip to content
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

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

Open
prioux opened this issue Mar 7, 2023 · 3 comments · May be fixed by #1331
Open

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

prioux opened this issue Mar 7, 2023 · 3 comments · May be fixed by #1331
Assignees

Comments

@prioux
Copy link
Member

prioux commented Mar 7, 2023

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
Copy link
Contributor

MontrealSergiy commented May 3, 2023

more like not user-friendly than totally bad.

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

@MontrealSergiy
Copy link
Contributor

MontrealSergiy commented May 3, 2023

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 />' +

@MontrealSergiy MontrealSergiy self-assigned this May 3, 2023
@prioux
Copy link
Member Author

prioux commented May 3, 2023

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

MontrealSergiy added a commit to MontrealSergiy/cbrain that referenced this issue May 4, 2023
MontrealSergiy added a commit to MontrealSergiy/cbrain that referenced this issue May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants