Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Customising Error Messages on $DB errors

Quote Reply
Customising Error Messages on $DB errors
I am interested in customizing the error message into displaying a custom template instead of the canned message. Not having played around with the GT:error much before could someone point me in the right direction with an example:

So I want to turn this:

Quote:


A fatal error has occured:
The column 'VIN' must be unique, and already has an entry '1111'. at vr_add.cgi line 85.


Please enable debugging in setup for more details.


Into displaying my custom template: print Links::SiteHTML::display('vr_add_fail', $tags);

this is the part of the code after an insert statement for example:

Code:
$c->insert( blah blah )

or die $GT::SQL::error;
should I put the print Links::SiteHTML::display('vr_add_fail', $tags) after the or die part?Crazy


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Customising Error Messages on $DB errors In reply to
Depending on how custom you need it, is changing admin-->misc-->error_message not detailed enough?


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Customising Error Messages on $DB errors In reply to
Hi Robert... in this case no. It is for a customers site, it it needs only affect this cgi file and particular instance.

Ideally, it would be nice to isolate just the "friendly" part of the message (in red), and put it into my own template. And this is not something I want done system wide on the customers site, just for this particular error.

A fatal error has occured:
The column 'VIN' must be unique, and already has an entry '1111'. at vr_add.cgi line 85.


Please enable debugging in setup for more details.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jul 7, 2002, 8:07 AM
Quote Reply
Re: [Ian] Customising Error Messages on $DB errors In reply to
Still having probs with thisUnsure. I am sure there must be a simple'ish solution.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jul 7, 2002, 1:46 PM
Quote Reply
Re: [Ian] Customising Error Messages on $DB errors In reply to
Change sub fatal in Links.pm. Or if it's for a separate cgi script, add the line:

local $SIG{__DIE__} = \&MyModule::my_fatal;

and in MyModule.pm create a function my_fatal, modelled after Links::fatal.

EDIT: do you really want your script to die after this error, don't you want to just print out the error, and go on with the script, i.e. something like

my $error;
$table->insert($record) or $error = $GT::SQL::error;
if ($error) {
do something useful here ...
}

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Jul 7, 2002, 1:56 PM
Quote Reply
Re: [yogi] Customising Error Messages on $DB errors In reply to
Hi Ivan, fancy seeing you around on this quiet Sunday.

Thanks very much!

Yes, I think you are right... I don't want it to die. Just display a custom error message.

And your script will do that nicely!!! This is precisely the example I was looking for.

Cool


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jul 7, 2002, 2:04 PM