PJanisio / myuplinkapi

API connector for Nibe MyUplink
GNU Affero General Public License v3.0
0 stars 0 forks source link

Create class method for curl and api errors #6

Closed PJanisio closed 4 months ago

PJanisio commented 4 months ago

This chunk of code can be improved:


$data = json_decode($c_answer, TRUE);
        //204 is a special htttp response f.e for API ping
        if ($data == NULL or curl_getinfo($c, CURLINFO_HTTP_CODE) != 200)
        {

            //we didnt received answer
            if (curl_error($c) != NULL)
            {
                echo $this->msg('Error resolving answer: ' . curl_error($c));
                $this->redirectMe($this->config['redirectUri'], 3);
            } else {
                echo $this->msg('Error resolving answer: '.curl_getinfo($c, CURLINFO_HTTP_CODE). $c_answer);

                if (isset($c)) {
                    curl_close($c);
                }

                return FALSE;
            }
PJanisio commented 4 months ago

Done: https://github.com/PJanisio/myuplinkapi/commit/06b7991dc9a8be639bb8bda67820fe391f5eb59a