Ajax requests

siburny

Joined: 2012-03-27
Posts: 40
Posted: Wed, 2012-05-23 21:12

I've recently discovered that Gallery doesn't handle errors in AJAX requests. Example: I had bad characters in the Album name and when I go to delete that album, Ajax request would fail with 500 status code, but spinner and dialog would still be visible on screen like "request is still being processed".

To rectify this, I added an error handler in gallery.dialog.js file (put it right after or before "success" ajax handler in "_ajaxify_dialog" function):

error: function(xhr, ajaxOptions, thrownError) {
$("#g-dialog").html(xhr.responseText);
self._set_title();
var size = $.gallery_get_viewport_size();
$("#g-dialog").dialog('option', 'width', size.width() - 200);
$("#g-dialog").dialog("option", "position", "
},

What it does is it replaces HTML of the dialog with text of the error message that server returned. At least now I not only know immediately that requests failed, I also get a full error message (in my case Kahana exception with stack trace).

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25956
Posted: Wed, 2012-05-23 22:35
Quote:
I had bad characters in the Album name

Can you explain how that happened?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
siburny

Joined: 2012-03-27
Posts: 40
Posted: Thu, 2012-05-24 14:18

They are not bad per se, but they are not being validated. My album name has many periods "." like this "2011.12.31-Happy.New.Year", and Gallery apparently doesn't allow multiple periods in the name. But when you add images using Server Add module, names are not totally validated, and albums are created as they are (with many periods), and (of course) I can't delete them afterwards :)

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25956
Posted: Thu, 2012-05-24 15:33

OK, thanks for the explanation. I'm trying to reproduce this but I'm having trouble.
I created a directory on the server called: 2011.12.31-Happy.New.Year
added a image to that directory
Used server add to add that directory. It did not add that directory.

Trying to manually create that album I get a validation.illegal_data_file_extension in the inernet address field.

Got a better step by step procedure on how to reproduce?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
siburny

Joined: 2012-03-27
Posts: 40
Posted: Thu, 2012-05-24 15:50

I figured it out! Look at this commit from May 17: https://github.com/gallery/gallery3/commit/9e2ea2ffedb22f83137db4e5ba4c06b91f11e09d#modules/gallery/models/item.php

When I used Server Add (several weeks ago), that code wasn't there and I was able to add that album. Several days ago I merged with upstream that added extra validation (line 807 in /module/gallery/models/item.php):

// Do not accept files with double extensions, they can cause problems on some
// versions of Apache.
if (substr_count($this->name, ".") > 1) {
$v->add_error("name", "illegal_data_file_extension");
}

Now that check "breaks" my installation, because every album has multiple periods in the name and hence I can't delete them :)

Login or register to post comments
siburny

Joined: 2012-03-27
Posts: 40
Posted: Thu, 2012-05-24 16:00

But the point of this thread is to add some kind of indication that AJAX request failed, no matter what went wrong :)

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25956
Posted: Thu, 2012-05-24 16:09

Ok, I file a ticket.
Thanks for the leg work!

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
siburny

Joined: 2012-03-27
Posts: 40
Posted: Thu, 2012-05-24 16:12

There is a ticket from 3 year ago about that :) http://sourceforge.net/apps/trac/gallery/ticket/236

I'll add a comment and the snippet.

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25956
Posted: Wed, 2012-06-06 14:11
Login or register to post comments