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

Improve error handling and logic #58

Closed

Commits on Mar 16, 2023

  1. Change URL formatting for ACF, GF, WPML

    Use `http_build_query()` to improve readability and reduce risk of errors.
    mcaskill committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    23e7a41 View commit details
    Browse the repository at this point in the history
  2. Change HTTP request method for ACF-E, GF, PLL

    Use GET instead of POST to better match the verb to the request and for consistency between downloaders.
    mcaskill committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    2810340 View commit details
    Browse the repository at this point in the history
  3. Clean-up usage of exceptions

    Changed:
    - Throw `InvalidArgumentException` instead of `UnexpectedValueException` when dealing with an unsupported package in Ninja Forms, PublishPress Pro, and WPML.
    - Throw `UnexpectedValueException` if the decoded/unserialized API response is not an array.
    - Improved messages to clarify errors from API.
    - Fixed and improved PHPDoc tags to document exceptions.
    mcaskill committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    7d3aa9e View commit details
    Browse the repository at this point in the history
  4. Clean-up Http class

    Changed:
    - Use booleans intead of integers for cURL options.
    - Compile URL in GET request earlier to organize cURL options similarly to POST request.
    mcaskill committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    0b1c8af View commit details
    Browse the repository at this point in the history
  5. Improve Http class request and response handling

    Changed:
    - Added protected method `request()` to aggregate the execution of the request, handling of the response, and closing of the cURL handler.
    - Added cURL option `CURLOPT_FAILONERROR` to fail if the response is >= 400.
    - Throw `RuntimeException ` if the request failed.
    - Fixed and improved PHPDoc tags.
    mcaskill committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    fb0c1ab View commit details
    Browse the repository at this point in the history
  6. Refactor plugin abstraction and Http usage

    Changed:
    - Replaced `getDownloadUrl()` in EDD plugins with a new protected method `getDownloadUrlFromApi()` that only handles the request for the download URL response object.
    - Replaced `extractDownloadUrl()` with `getDownloadUrl()` in `AbstractEddPlugin` that retrieves the response to parse from the plugin's `getDownloadUrlFromApi()`.
    - Wrapped requests with `Http` in a try/catch to intercept cURL exceptions and wrap them in a plugin-aware exception.
    mcaskill committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    cee1cf5 View commit details
    Browse the repository at this point in the history

Commits on Jun 9, 2023

  1. Remove default value for $url arguments in Http class

    A URL is necessary for requests.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    24eb239 View commit details
    Browse the repository at this point in the history
  2. Update block comments in AbstractPlugin

    Changed:
    - Removed extraneous property descriptions.
    - Rephrased description of `$slug` property to be more specific.
    - Added missing `$slug` method parameter.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    1e8f528 View commit details
    Browse the repository at this point in the history
  3. Fix HTTP request method for ACF-Extended

    Amends cee1cf5
    
    Accidentally reverted back from GET to POST.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    378ade7 View commit details
    Browse the repository at this point in the history
  4. Decouple API URL and query parameters

    Decoupled API URL and API URL query parameters from its HTTP query building and URL concatenation, and HTTP request call.
    
    This allows the base URL and query parameters to be more readable from their final concatenated URL or HTTP request call.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    efdb917 View commit details
    Browse the repository at this point in the history
  5. Decouple version from API URL query parameters and version check

    This ensures compatibility with the classes' `$version` property being potentially empty, presuming a request for the latest version.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    e667513 View commit details
    Browse the repository at this point in the history
  6. Add getPackageName() method to AbstractPlugin

    To reduce repetition, and risk of mistakes, when formatting the plugin's Composer package name. The package name is used in the messaging of most exceptions thrown.
    
    Storing vendor name as a namespace
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    f4ad7ec View commit details
    Browse the repository at this point in the history
  7. Improve Http class

    Changed:
    - Moved shared cURL options to `request()` method.
    - Catch any exception from `Http` requests.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    fa45ae8 View commit details
    Browse the repository at this point in the history
  8. Improve error handling for EDD plugins

    Separated JSON decoding error handling from HTTP request/response error handling.
    
    By using `json_last_error()`, we can provide a more precise error for end users as opposed to just checking if its an array.
    
    Output a truncated excerpt of the response body if JSON decoding fails to give a hint of what the issue might be.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    134926b View commit details
    Browse the repository at this point in the history
  9. Improve error handling for Gravity Forms

    Separated unserialization error handling from HTTP request/response error handling.
    
    Wrapped unserialization in try/catch to intercept any throwables from unexpected objects in their unserialization handlers. Gravity Forms is supposed to return an associative array but could be compromised.
    
    Output a truncated excerpt of the response body if unserialization fails to give a hint of what the issue might be. Ideally, add an error handler to catch the PHP notice that is raised by `unserialize()`.
    mcaskill committed Jun 9, 2023
    Configuration menu
    Copy the full SHA
    ab73a24 View commit details
    Browse the repository at this point in the history