Laravel jQuery Ajax Error 500 – SoapFault Exception received from JSON Server

You sometimes get a jQuery Ajax Error 500. The Homestead /var/logs/error.log will show you nothing and in your laravel.log nothing shows either. Fortunately in your console you did get an error and as it is a JavaScript or to be specific a jQuery Ajax error. So that is a start. But how to get to the bottom of this?

Background Information

As a heads up here some background information. We are using a Laravel Transip Package by Hidde. It is used to connect to a service provider (Transip) via  a Soap API. And we use jQuery Ajax calls to make requests to this interface. We are working locally on a Laravel Homestead box and bumped into this error 500 issues and decided to dive deep into this package and the API provided by the service provider.

General jQuery Error

At first you will see the general error message and what functions it is related to (code modified somewhat names wise):

GET http://domain.test/backend/check-availability?querystring=value 500 (Internal Server Error)
 send @ jquery.min.js:4
 ajax @ jquery.min.js:4
 checkSomethingAvailability @ something-management?project=97:503
 onclick @something-management?project=97:307

jQuery Send Error

With the JS beautified you can go to the line where the error occured. In this case line 4208 of jQuery formatted:

jquery.min.js:formatted:4208 GET http://domain.test/dashboard/check-domain-availability?domain=domain.io 500 (Internal Server Error)
 send @ jquery.min.js:formatted:4208
 ajax @ jquery.min.js:formatted:3990
 checkDomainAvailability @ domain-management?project=97:503
 onclick @ domain-management?project=97:307

There you can see

g.send(b.hasContent && b.data || null)

and a cross next to it. When you hover on it you see this message

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

So sending the data it failed to load something.

SoapFault

Then you decide to check the response for the actual file in the console by clicking the file under the Network Tab (Chrome Inspector):

SoapFault

That shows an exception. One that was not logged in the error log…. And there appears to be a SoapFault as you can see.

The actual error is this one:

(1/1) SoapFault
 Exception received from JSON Server: Timestamp outside maximum allowed window of 15 minutes; given timestamp was: 1518507112 (timestamp: 0.13471400 1520058610)

in AbstractApi.php (line 36)
 at SoapClient->__call('checkAvailability', array('domain.com'))
 in AbstractApi.php (line 36)
 at AbstractApi->call('domainService', 'checkAvailability', array('domain.com'))
 in Domain.php (line 20)
 at Domain->checkDomain('domain.com')
 in DomainManagementController.php (line 81)
 at DomainManagementController->checkAvailability(object(Request), object(DomainManager))
 at call_user_func_array(array(object(DomainManagementController), 'checkAvailability'), array(object(Request), object(TransIPManager)))
 in Controller.php (line 55)
 at Controller->callAction('checkAvailability', array(object(Request), object(TransIPManager)))
 in ControllerDispatcher.php (line 44)
 at ControllerDispatcher->dispatch(object(Route), object(DomainManagementController), 'checkAvailability')
 in Route.php (line 203)
 .......

AbstractApi Call

in AbstractApi.php of the Laravel package in question on line 36 mentioned in the error report we have

protected function call($service, $method, array $parameters = [])
{
return$this->getSoapClient($service, $method, $parameters)->__call($method, $parameters);
}
which is called from Domain.php with this function
public function checkAvailability($domainName)
{
return$this->call(self::SERVICE, 'checkAvailability', [$domainName]);
}

JSON Server Exception

The Laravel API Package throws a SoapFault every time there is an issue making  a connection. The username and key should be fine. I checked. The exception:

Exception received from JSON Server: Timestamp outside maximum allowed window of 15 minutes; given timestamp was: 1518507112 (timestamp: 0.13471400 1520058610)

Timezone Solution

Perhaps a timezone issue as Thomas at the Facebook PHP Group suggested. Logical when I think about it now, but well.  So I did a

ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

inside after.sh to make it Amsterdam time like the hoster, but it did not pick it up.  And the Homestead date was February the 13th which was also completely off.

However when I did a:

sudo timedatectl set-timezone Europe/Amsterdam

inside the Vagrant Box and a hard reboot I got where I wanted to be. It  did force me to do a service nginx restart

vagrant@homestead:~$ service nginx restart
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'nginx.service'.
Authenticating as: vagrant,,, (vagrant)
Password: 
==== AUTHENTICATION COMPLETE === 

to get things going.. However I go the CET time and correct date:

date
Sat Mar  3 12:25:46 CET 2018

And once I had that all started working!

NB Funnily the Box was set to ‘timezone’ => ‘Europe/Amsterdam’, in config/app.php already..

Tagged in : Tagged in : , , ,
Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.