http://qs1969.pair.com?node_id=11137242

Bod has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for some debugging help please
Ideally I would like something like a fatalsToFile equivalent to the CGI::Carp fatalsToBrowser.

I have what appears to be the same issue on two different websites. They are both on the same shared hosting but otherwise totally independent.

The most critical issue is with a script that gets booking information from OTAs, Online Travel Agents (Airbnb, Booking.com, etc) using their API to provide an ICS file. Our booking platform checks this information as well as our own booking database to show customers our availability. Our script caches the ICS file for 30 minutes. This script has an API that our booking platform calls to get a simple text file which lists the property number and either 'available' or 'booked'. When a customer commits to book, the API is called again but with a force parameter to bypass the cache.

Except the API returns a 500 error when called from the booking platform. But I cannot replicate it when calling the script using a web browser.

Here's the code we had working. I know there are some bad practices in there but this is legacy code and will get improved in due course. The important thing is that is was working fine until recently and I am not aware of anything that could have caused the change:

if (!defined @avail) { foreach (split /\n/, &get("https://$ENV{'HTTP_HOST'}/cgi-bin/booki +ng.pl?command=check&st=$data{'st'}&ed=$data{'ed'}&force=$data{'force' +}", $availability);) { chomp; my ($k, $v) = split/,/; $avail[$k] = $v; } }
The &get is from LWP::Simple.
To try and understand what was going on, I changed the code to this:
my $availability = LWP::Simple::get("https://$ENV{'HTTP_HOST'}/cgi-bin +/booking.pl?command=check&st=$data{'st'}&ed=$data{'ed'}&force=$data{' +force'}"); print "->$availability<-\n"; if (!defined @avail) { foreach (split /\n/, $availability) { chomp; my ($k, $v) = split/,/; $avail[$k] = $v; } }
and found that $availability was empty.
my $availability; my $response = LWP::Simple::getstore("https://$ENV{'HTTP_HOST'}/cgi-bi +n/booking.pl?command=check&st=$data{'st'}&ed=$data{'ed'}&force=$data{ +'force'}", $availability); print qq[("https://$ENV{'HTTP_HOST'}/cgi-bin/booking.pl?command=check& +st=$data{'st'}&ed=$data{'ed'}&force=$data{'force'}")\n]; print "->$availability<-\n"; print "$response\n";
This shows that the response code is 500.
Copying the printed URL into a web browser gives the text output that I would expect.

I have checked the error logs provided to me by cPanel and nothing shows up at all.

Any ideas why a script would return a 500 error when called by LWP::Simple get but not when called by Chrome?
There is nothing in the script that checks the user agent and it was previously working.

I have a similar, but intermittent problem on another site. This time the script is called from the browser using the fetch API. The script returns a JSON object. Again, the script returns a 500 error some of the time but works as predicted most of the time (unlike above which fails every time). Again I am at a loss how to debug this as I cannot catch the errors to find what or where they are.

This is the Javascript from the Template file that calls the Perl API which generates the error:

fetch('/api/', { method: 'POST', body: 'a=[% token %]&u=[% user %]&q=getWays&' + request, }).then(response => response.json()) .then(data => { document.getElementById('mapmsg').innerHTML = ''; if (data[0][0].status == 'success') { plotWays(data); } else { document.getElementById('timeoutbox').style.display='block +'; } }) .catch(error => { console.log(error.message); });

If I had any hair, I would be pulling it out...