My question is I am accessing some external rest api like getServices if the get services response is like this
{
"status": 200,
"data": [
{
"country": "india",
"qualfication": "B.tech",
"educationId": 13,
"city": "Mathurafgddsfwf",
"endDate": null,
"clgUniversity": "amar Nath",
"startDate": "2010-05-22"
}
]
}
everything is working fine for the above response from the external Api
but when the response is like this from external Api it is giving 500 error in browser
{
"status": 104,
"message": " not exist",
"data": []
}
my controller code is
public function getEducation(Request $request){
// dd($request);
$cookie = \Cookie::get('datastore');
$dataJson=json_decode($cookie,true);
$username=$dataJson['data']['username'];
$token= $dataJson['data']['token'];
$phoneSecurity= $dataJson['data']['phone'];
$userId=$dataJson['data']['userId'];
$client =new Client();
$data=array( "username"=>$username,
);
$dataJson=json_encode($data);
$headers['Content-Type']="application/json";
$headers['X-Access-Token']=$token;
$response=$client->request('POST',
'http://localhost:8084/api/users/getUserEducationDetails'
,array("headers"=>$headers,"body"=>$dataJson));
$body=$response->getBody()->getContents();
$resText=json_decode($body,true);
if( $resText['status']==200)
return response()->json($resText);
if($resText['status']==104)
{
$newData=array("status"=>"104");
$newData=json_encode($newData);
$resText=$newData;
}
return response()->json($resText);
}
In short when the external api returning response like this { "status": 104, "message": " not exist", "data": [] } laravel gives 500 internal server error
And the error showed inside the network tab inside response is
GuzzleHttp\Exception\ClientException: Client error: `POST http://localhost:8084/api/enimm/users/getUserEducationDetails` resulted in a `404 Not Found` response:
{"status":104,"message":" not exist","data":[]}
in file C:\xampp\htdocs\OodeatSocialFinal\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire