Skip to content

Exception thrown by the WooCommerce REST API wrapper #5

Description

@anghelalexandra

Describe the bug
REST API routes for retrieving products, categories, etc. are throwing an exception.

(
    [request:Automattic\WooCommerce\HttpClient\HttpClientException:private] => Automattic\WooCommerce\HttpClient\Request Object
        (
            [url:Automattic\WooCommerce\HttpClient\Request:private] => .../wp-json/wc/v2/products/categories
            [method:Automattic\WooCommerce\HttpClient\Request:private] => GET
            [parameters:Automattic\WooCommerce\HttpClient\Request:private] => Array
                (
                )

            [headers:Automattic\WooCommerce\HttpClient\Request:private] => Array
                (
                    [Accept] => application/json
                    [User-Agent] => WooCommerce API Client-PHP/1.3.0
                )

            [body:Automattic\WooCommerce\HttpClient\Request:private] => 
        )

    [response:Automattic\WooCommerce\HttpClient\HttpClientException:private] => Automattic\WooCommerce\HttpClient\Response Object
        (
            [code:Automattic\WooCommerce\HttpClient\Response:private] => 401
            [headers:Automattic\WooCommerce\HttpClient\Response:private] => Array
                (
                    [Server] => nginx
                    [Date] => Fri, 10 Aug 2018 15:21:08 GMT
                    [Content-Type] => application/json; charset=UTF-8
                    [Transfer-Encoding] => chunked
                    [Connection] => keep-alive
                    [X-Robots-Tag] => noindex
                    [Link] => <.../wp-json/>; rel="https://api.w.org/"
                    [X-Content-Type-Options] => nosniff
                    [Access-Control-Expose-Headers] => X-WP-Total, X-WP-TotalPages
                    [Access-Control-Allow-Headers] => Authorization, Content-Type
                    [Set-Cookie] => pwacommerce_load_app=0; expires=Sun, 12-Aug-2018 15:21:08 GMT; Max-Age=172800; path=/
                    [X-Powered-By] => Loading
                )

            [body:Automattic\WooCommerce\HttpClient\Response:private] => {"code":"woocommerce_rest_cannot_view","message":"Lo siento, no puedes listar los recursos.","data":{"status":401}}

To Reproduce
Steps to reproduce the behavior:

  1. Create WooCommerce REST API key / secret
  2. Save key / secret in the PWACommerce settings page
  3. Go to the following URL: https://yourdomain/wp-json/pwacommerce/categories/
  4. A HTTP 500 error is displayed.

Expected behavior
Return JSON data so it can be used by the app.

WordPress / WooCommerce setup

Additional context
Exception catching should also be added so the HTTP 500 status can be replaced with a user friendly message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions