Error Handling!

rimbeaux
rimbeaux's picture

Joined: 2006-10-17
Posts: 48
Posted: Wed, 2007-09-12 14:46

Is there a way to specify error handling? Whenever someone moves or deletes a picture, the original link goes bad and you get an ugly message, "Unable to initialize embedded Gallery. You need to configure your embedded Gallery." which contains a link to admin/settings/gallery, which folks aren't authorized to go to. I'd much rather see an "link no longer valid, that image was moved or deleted" message or better yet that message and the search page.

I tried using permalinks, but it doesn't work for me and I haven't had the time to muck with it. It was challenging enough getting url rewrite, embedding, search, etc all working!

My gallery, http://www.cheddarmongers.org/prod/gallery is embedded into Drupal 4.7.6

Thanks!


Gallery version = 2.2.2 core 1.2.0.4
PHP version = 5.1.4 cgi-fcgi
Webserver = Apache
Database = mysql 4.0.27-max-log, lock.system=flock
Toolkits = Exif, Getid3, Gd, SquareThumb, Thumbnail, Ffmpeg, LinkItemToolkit
Acceleration = none/3600, none/3600
Operating system = Linux linhost223.prod.mesa1.secureserver.net 2.4.21-27.ELsmp #1 SMP Wed Dec 1 21:59:02 EST 2004 i686
Default theme = matrix
gettext = enabled
Locale = en_US
Browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
Phpinfo: http://www.cheddarmongers.org/prod/phpinfo.php

Visit my gaming site at www.cheddarmongers.org

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Fri, 2007-09-14 15:03

There is no advanced error handling available with the gallery 4.7 module. But we have improved that in the latest gallery 5.x-2.x version. As a workaround you could simply edit the message string and remove the link, etc.

 
rimbeaux
rimbeaux's picture

Joined: 2006-10-17
Posts: 48
Posted: Fri, 2007-09-14 15:16

Great idea! Where is the error message string configured? Replacing the message will statisfy me for now.

Visit my gaming site at www.cheddarmongers.org

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Fri, 2007-09-14 16:01

The string is located in gallery.module (function gallery_page(), line 199+). You can change $err_msg = t('Unable ...'); to whatever you wish.

 
rimbeaux
rimbeaux's picture

Joined: 2006-10-17
Posts: 48
Posted: Fri, 2007-09-14 16:45

Done, thanks! I changed it to:

if (!$success) {
gallery_error(t('Unable to find the picture...'), $ret);
$err_msg = t('The picture cannot be found; it may have been moved or deleted. Please <a href="%link"> search the gallery</a> for your picture!',
array('%link' => url('search/gallery')));

Now if only I can figure out how to put the search field in that reply, it would be even cooler.

The downside is now the error log shows 3 entries for the error, one "unable to find the picture," and 2 "unable to initialize the embedded gallery." Fortunately, it looks like the site visitor only sees the "unable to find picture" message and the link to search.

Visit my gaming site at www.cheddarmongers.org

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Fri, 2007-09-14 16:59

I cant remember the 4.7 module in details atm, but on the settings page there should be an option 'Error logging'. You should disable 'Output to browser' there. Then what is passed to gallery_error() will show up in the watchdog only. The $err_msg variable is still printed to screen. However in your case you'd probably want a different solution. Try something like:
if (!$success) {
drupal_set_message('Unable to find image ...', 'notice');
drupal_goto('search/gallery');
}
This should redirect your users to the search page and display 'Unable to ...' message on that screen.
I'm currently away from my dev environment, but I hope the above is correct :)

 
rimbeaux
rimbeaux's picture

Joined: 2006-10-17
Posts: 48
Posted: Fri, 2007-09-14 20:59

That's an elegent solution! What does 'notice' mean?

But now it doesn't log an error in watchdog anymore... what do I need to add?

I replaced this from the origional:

if (!$success) {
gallery_error(t('Unable to initialize embedded Gallery'), $ret);
$err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link">
configure your embedded Gallery</a>.',
array('%link' => url('admin/settings/gallery')));
return $err_msg;
}

with this:

if (!$success) {
drupal_set_message('Image not found; it may have been moved or deleted. Please search for your image:', 'notice');
drupal_goto('search/gallery');
}

Visit my gaming site at www.cheddarmongers.org

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Fri, 2007-09-14 23:17
Quote:
What does 'notice' mean?

'notice' displays a normal message on gray background. 'error' displays an error on red background. and 'message' (or nothing) displays a success message on green background. Its your choice ;) But I thought a neutral message would be best here.

Quote:
But now it doesn't log an error in watchdog anymore... what do I need to add?

Oh, yes! I should have thought a second before posting the message above. You can add back the gallery_error() call (somewhere before drupal_goto()). Its responsible for logging the message to watchdog. But make sure to disable 'Output to browser' as explained above or you will get both messages displayed.

 
rimbeaux
rimbeaux's picture

Joined: 2006-10-17
Posts: 48
Posted: Sat, 2007-09-15 10:58

All good now, thanks! Here's the update:

if (!$success) {

drupal_set_message('Image not found; it may have been moved or deleted. Please search for your image:', 'notice');
gallery_error(t('Bad link in gallery'), $ret);
drupal_goto('search/gallery');
}

Visit my gaming site at www.cheddarmongers.org

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Sat, 2007-09-15 11:20

You inspired me to add an option for this feature to the latest module version. So if you ever update to D5+ this feature will wait there for you ;)

 
rimbeaux
rimbeaux's picture

Joined: 2006-10-17
Posts: 48
Posted: Sat, 2007-09-15 13:01

Excellent!

One refinement that would be way cool; if the image name could be put into the search box.

For example, if the visitor tried www.cheddarmongers.org/prod/pic/badlink.jpg.html it would be cool if badlink would show up in the search box already. I'm sure its possible... Hmm... even cooler? If it would go ahead and search and show the search results, such as, "Your image could not be found at that link. These are the closest matches..."

What do you think?

By the way; I did uncheck the "output to browser"

Visit my gaming site at www.cheddarmongers.org

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Sat, 2007-09-15 13:26

The only problem with your latest idea is that in many cases you dont know the 'title' of the G2 item. 1. Its only part of the url if clean urls are enabled (otherwise you get stg. like '?q=gallery&g2_itemId=24') and 2. even with a clean url you dont know what part of the url is the *keyword*. Remember that you can change the url pattern in G2 to almost everything. Its not necessarily '/pic/title.jpg.html' ...

However you could in principle redirect to 'search/gallery/*keyword*' instead of just 'search/gallery'. This directly provides you the search results for *keyword*. In case you have a known url format, you can use arg(x) to extract a fragment from the url. 'x' is the position, e.g. abc/def/ghi: arg(0) = 'abc', arg(1) = 'def', ...
If you known the title is at position 3 the code would look like this: drupal_goto('search/gallery/'. arg(3));

Hope this helps.