Discussions

Ask a Question
Back to All

404 Error

Hello,

I was working the API and I am trying to set up some error messages. When the domain name is not correct, the api should return a code of 404, which it does but inside the response. The http code is in fact 200 which is not correct. Here is my code: 

$slash_tag = $user.'/vehicle/'.$vehicle_id;
echo console_log($slash_tag);
$domain_data["fullName"] = "renntapasdas.com"; // messed up domain name
$post_data["destination"] = $destination;
$post_data["domain"] = $domain_data;
$post_data["slashtag"] = $slash_tag;
$post_data["title"] = $title;
$ch = curl_init("https://api.rebrandly.com/v1/links");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"apikey: NO!", // Do in fact have this but not showing it
"Content-Type: application/json"
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
$result = curl_exec($ch);
$response = json_decode($result, true);
/ returns {
"message": "Not found",
"httpCode": 404,
"code": "NotFound",
"source": "domain",
"id": "renntapasdas.com"
}
/
echo console_log("Link: ", $response);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Should return a 404 but returns a 200
echo console_log("HTTP Code: ", $httpcode);
curl_close($ch);
if ($httpcode==403) {
if ($response['errors'][0]['code'] == 'AlreadyExists') {
return 'renntap.com/'.$slash_tag;
} else {
return '';
}
} else if($httpcode==200) { // therefore this if statement is true when it shouldn't be
return $response['shortUrl'];
} else {
return '';
}

Any suggested work arounds?