Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: CGI::Carp fatalsToFile

by tangent (Parson)
on Oct 06, 2021 at 02:56 UTC ( [id://11137250]=note: print w/replies, xml ) Need Help??


in reply to CGI::Carp fatalsToFile

You could try putting this at the top of the script:
use CGI::Carp qw(set_die_handler); BEGIN { sub handle_errors { my $msg = shift; print "Content-Type: text/html\n\n"; print "$msg"; } set_die_handler(\&handle_errors); }
This will change the server's response code from 500 to 200 and would give you content like:
[Wed Oct 5 23:53:36 2021] test.cgi: Died at /web/test.cgi line 15.
However, the fact that the script you are calling with LWP::Simple does not appear in the logs would suggest that it is not actually being called.

I would not discount the role of user-agent - non-standard user-agents can be blocked to prevent web scraping. Maybe something at the server level was updated or reconfigured by your hosting company? To test you will need to use LWP::UserAgent directly.

use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/5.0'); # play with this string my $response = $ua->get('http://localhost/web/test.cgi'); if ($response->is_success) { print $response->decoded_content; } else { print $response->status_line; }

Replies are listed 'Best First'.
Re^2: CGI::Carp fatalsToFile
by Bod (Parson) on Oct 06, 2021 at 16:25 UTC

    Thanks for the very helpful reply

    You could try putting this at the top of the script:
    use CGI::Carp qw(set_die_handler); BEGIN { sub handle_errors { my $msg = shift; print "Content-Type: text/html\n\n"; print "$msg"; } set_die_handler(\&handle_errors); }

    I'm going to write some test code so that I can properly test what is going on. It will probably have to wait until the weekend though. But this code has been a little confused!

    Is set_die_handler a method of CGI::Carp and set_die_handler(\&handle_errors); in the BEGIN block is overriding it?
    Or is something different happening here?

      Is set_die_handler a method of CGI::Carp and set_die_handler(\&handle_errors); in the BEGIN block is overriding it?

      set_die_handler is a method of CGI::Carp, but its purpose is to allow you to specify your own function to be executed "any time a script calls "die", has a syntax error, or dies unexpectedly at runtime". See the docs for more.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-19 17:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found