I have an interface to an API that returns a json object.
The normal response would be something like
I decode the object as follows and check to see if it is ok.
The problem exists if there is an error.
The JSON then looks like
If I code it to check the error it will blow up with an error from Yii as follows:
Undefined property: stdClass::$error_id
Because the error does not exist.
How best to handle this ?
Is there a Yii function to check it?
Something like isset( $obj->response->error_id ) ?
This problem is killing me, I can't handle exceptions very gracefully!
Thanks for any advice!
The normal response would be something like
{ "response": { "status":"OK","id":241 }}
I decode the object as follows and check to see if it is ok.
$obj = json_decode($jsonObject); $ok = $obj->response->status;
The problem exists if there is an error.
The JSON then looks like
{ "response": { "error_id":"NOAUTH",....}} and I would get it's error code $error_id = $obj->response->error_id;
If I code it to check the error it will blow up with an error from Yii as follows:
Undefined property: stdClass::$error_id
Because the error does not exist.
How best to handle this ?
Is there a Yii function to check it?
Something like isset( $obj->response->error_id ) ?
This problem is killing me, I can't handle exceptions very gracefully!
Thanks for any advice!