midtrans-php icon indicating copy to clipboard operation
midtrans-php copied to clipboard

TODO: check whether HTTP request body exists, if not throw a proper error. To prevent confusing array-key not exist related err msg.

Open rizdaprasetya opened this issue 2 years ago • 1 comments

Current Unexpected:

https://github.com/Midtrans/midtrans-php/blob/4929d87da0db94404e69ba43b967a98701572370/Midtrans/Notification.php#L23-L28

On that function,

  • when HTTP request come and that function get executed,
    • IF the HTTP request body is not exist, THEN it will unexpectedly throw error of Trying to access array offset on value of type null on line 26.
    • which could be misleading because it just throw array-key related error message without actually explaining what went wrong.

Expected:

  • The code should better check
    • Is parsing of the HTTP request body succeeds ?
    • Is json_decode succeeds ?
    • is $raw_notification['transaction_id'] exists?
    • optionally: Is the HTTP request valid HTTP POST method?
  • Then the code should throw a more user-friendly error message that indicate what failed.
    • So that user could understand better.

Note:

  • This will not prevent the actual root cause of issue that triggers the exception. But at least by letting user know what process failed, they can have better insight in investigating the actual root cause. e.g. HTTP Request body is missing from the request, then they can check their infra is something removing the body.

rizdaprasetya avatar Nov 22 '22 07:11 rizdaprasetya

Duplicate or could be merged with this backlog.

rizdaprasetya avatar Nov 22 '22 07:11 rizdaprasetya