Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rizdaprasetya opened this issue Nov 22, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@rizdaprasetya
Copy link
Collaborator

rizdaprasetya commented Nov 22, 2022

Current Unexpected:

public function __construct($input_source = "php://input")
{
$raw_notification = json_decode(file_get_contents($input_source), true);
$status_response = Transaction::status($raw_notification['transaction_id']);
$this->response = $status_response;
}

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 rizdaprasetya added the enhancement New feature or request label Nov 22, 2022
@rizdaprasetya
Copy link
Collaborator Author

Duplicate or could be merged with this backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant