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...


In reply to CGI::Carp fatalsToFile by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.