TODO: check whether HTTP request body exists, if not throw a proper error. To prevent confusing array-key not exist related err msg.
rizdaprasetya opened this issue · 1 comments
rizdaprasetya commented
Current Unexpected:
midtrans-php/Midtrans/Notification.php
Lines 23 to 28 in 4929d87
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.
- IF the HTTP request body is not exist, THEN it will unexpectedly throw error of
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 commented
Duplicate or could be merged with this backlog.