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

Improved error handling for HTTP Response isSuccess method #136

Open
AdamChildrenPMAHR opened this issue Aug 25, 2023 · 1 comment
Open

Comments

@AdamChildrenPMAHR
Copy link

What is the issue:

Undefined property: stdClass::$success

The method is assuming that the success property will always be passed as part of the content body. Pipedrive does not pass this key on unsuccessful response codes (404 in this use case) so this will cause a status 500 from the dependency.

Where is the cause of the issue

File

vendor/devio/pipedrive/src/Http/Response.php

Codeblock

Line 53
    /**
     * Check if the request was successful.
     *
     * @return bool
     */
    public function isSuccess()
    {
        if (! $this->getContent()) {
            return false;
        }

        return $this->getContent()->success;
    }

Resolution

You can either use isset in the conditional statement or the return.

As there may be at some point a success property passed for status codes, it's probably best to use it in the if statement for this use case.

    /**
     * Check if the request was successful.
     *
     * @return bool
     */
    public function isSuccess()
    {
        if (! $this->getContent() || ! isset($this->getContent()->success)) {
            return false;
        }

        return $this->getContent()->success;
    }
@gabrielpeixoto
Copy link

I have the same error

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

No branches or pull requests

2 participants