Welcome Guest, Not a member yet? Register   Sign In
curlrequest error handling
#5

(This post was last modified: 06-19-2021, 11:15 PM by chakycool.)

try {
$response = $this->getToken($keys);
print_r($response);
}

catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}


private function getToken($data){

$body = '{"username":"[email protected]","password" : "'.$data->pw.'"}';
$client = \Config\Services::curlrequest();
$result = $client->setBody($body)->request('post', $data->url.'/v1/login/', [
'headers' => [
'Content-Type' => 'application/json',
'x-api-key' => $data->key
]
]);
return json_decode($result->getBody());
}

Sorry I didn't share the code before. Now on the code above I'm passing a invalid email and I end up with an error (CodeIgniter\HTTP\Exceptions\HTTPException).
If all is good no errors.

I found the problem

Add the "\" to "Exception" making it " \Exception"

Thank you so much incluebeer.
Reply


Messages In This Thread
curlrequest error handling - by chakycool - 06-16-2021, 04:31 AM
RE: curlrequest error handling - by includebeer - 06-17-2021, 02:47 PM
RE: curlrequest error handling - by chakycool - 06-19-2021, 12:54 AM
RE: curlrequest error handling - by includebeer - 06-19-2021, 09:06 AM
RE: curlrequest error handling - by chakycool - 06-19-2021, 11:12 PM
RE: curlrequest error handling - by includebeer - 06-20-2021, 04:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB