CommerceWeavers/SyliusSaferpayPlugin

Error handling causes php error and result in 500 on frontend

Closed this issue · 0 comments

What is the issue?

When other response type than application/json is returned then error handling logic cannot cope with response and results in fatal error at the time time hiding root cause behind a php error message like:

 PHP Warning:  Undefined array key "ResponseHeader" in /var/www/shop/vendor/commerce-weavers/sylius-saferpay-plugin/src/Client/ValueObject/ErrorResponse.php on line 140

which makes it really painful to troubleshoot. Message is not saved to transaction log table in Sylius admin as well.

It also causes error 500 on frontend which result in situation from which customer cannot recover (for example using other payment method).

Possible fix?

Support different response (content) types according to saferpay documentation

In paragraph about error handling it reads

The presence of an error message as specified in this document can be derived from the content type: if it’s application/json, then there is an error message present.

So some sort of check for content-type should be part of error handling process which seems to be missing at the moment:

$response = ErrorResponse::forAuthorize($result);

Possible further improvements?

Use logger service and always log raw response in case of error.