christoph-schaeffer / dhl-business-shipping

An unofficial library for the DHL business shipping soap API (Version 3.3) and the dhl shipment tracking rest API written in PHP.
MIT License
29 stars 8 forks source link

Unexcepted HTTP Code - 504 in Rest.php:96 #30

Closed Flaschenzug closed 1 year ago

Flaschenzug commented 1 year ago

In my error log I have the following Fatal error like 100 times:

Uncaught ChristophSchaeffer\Dhl\BusinessShipping\Exception\Tracking\DhlRestHttpException: Unexcepted HTTP Code - 504 
in /christoph-schaeffer/dhl-business-shipping/src/Protocol/Rest.php:96

#0 /christoph-schaeffer/dhl-business-shipping/src/Protocol/Rest.php(69): ChristophSchaeffer\Dhl\BusinessShipping\Protocol\Rest->handleHttpCodes(504, Object(ChristophSchaeffer\Dhl\BusinessShipping\Request\Tracking\getStatusForPublicUser), '<?xml version="...')
#1 /christoph-schaeffer/dhl-business-shipping/src/TrackingClient.php(105): ChristophSchaeffer\Dhl\BusinessShipping\Protocol\Rest->callRestFunction('<?xml version="...', Object(ChristophSchaeffer\Dhl\BusinessShipping\Request\Tracking\getStatusForPublicUser))
#2 /christoph-schaeffer/dhl-business-shipping/src/MultiClient.php(179): ChristophSchaeffer\Dhl\BusinessShipping\TrackingClient->getStatusForPublicUser(Object(ChristophSchaeffer\Dhl\BusinessShipping\Request\Tracking\getStatusForPublicUser))
#3 /file.php(533): ChristophSchaeffer\Dhl\BusinessShipping\MultiClient->getStatusForPublicUser(Object(ChristophSchaeffer\Dhl\BusinessShipping\Request\Tracking\getStatusForPublicUser))
#4 {main}
  thrown in /christoph-schaeffer/dhl-business-shipping/src/Protocol/Rest.php on line 96

The script is working normaly, but sometimes something is going wrong. Maybe it would make sense to add a try-catch exception for this kind of connection problem?

I will implement my own for the moment, just to prevent these errors from happening. But maybe it is interesting for the library too.

christoph-schaeffer commented 1 year ago

Hey @Flaschenzug,

sorry for the late reply!

This exception is thrown on purpose, because you got an error when trying to send data to the dhl api server. If i would add a try catch it would just not tell you that it didn't work, but still not work. However i definetly think that the error handling is very inconsistent atm. Im planning to do a refactor of several things for the next version where i want to work on the error handling as well.

What exactly would expect the lib to do if the dhl api server responds with 504? Im thinking of either transitioning to having error statuses or only use exceptions. It would help a lot to hear your Feedback about this 👍