Adds !empty check before json_decode#5616
Conversation
There was a problem hiding this comment.
Does this need some sort of logic too? So if $northstar_user ends up being null, how is the id, first_name, last_name etc being assigned that depends on getting an object from NS and not getting null?
There was a problem hiding this comment.
Maybe use something like this:
$this->user['drupal_id'] = $data->uid; // we by default pass the id to the new user property in the object
if(!empty($northstar_user)) {
$this->user['id'] = $northstar_user->_id,
$this->user['first_name'] = $northstar_user->first_name,
$this->user['last_name'] = $northstar_user->last_name,
$this->user['photo'] = $northstar_user->photo,
$this->user['country'] = $northstar_user->country,
}
I think that could work...
There was a problem hiding this comment.
Actually, scratch my suggestion above... it would make the returned data inconsistent and remove properties if null so wouldn't be as reliable...
instead, maybe just wrap the calls when assigning the properties on the user array to use the dosomething_helpers_isset():
...
'first_name' => dosomething_helpers_isset($northstar_user->first_name),
...
10ac4c2 to
02c1248
Compare
|
@weerd I'm getting this error: which refers to this line:
I'm not sure why it's saying that it's an undefined index and I looked it up on google - if I add an |
|
wait - just checked to test again and looks like it isn't work now because of the rebase - hold off on checking this please and I'll keep you updated! Sorry! @weerd |
|
@weerd okay now back in business! All should be working fine now. Just unsure about the comment above with the @ operator. Also, for some reason, |
|
@weerd for some reason, |
|
I looked into it, and it's how the |
|
@weerd tested |
|
yaaaas! |
There was a problem hiding this comment.
Didn't notice this before. No need for passing the ignore to the new static(). That's only needed for the Reportback class.
|
@weerd thank you! Made those two changes and tested again - still works! :) |
|
Awesome-sauce! 💃 Merge it! 👍 |
|
🎉 🎉 🎉 BEST DAY OF MY LIFE! |
Adds !empty check before json_decode
What does this PR do?
Adds a check to see if ns user is null and if so, do not try to json_decode to prevent error:
How should this be manually tested?
endpoint:
/api/v1/reportbacks.json?load_user=trueshould return user info. and not break. Works on local - tested by hard coding$northstar_user_info == NULLbefore new check and it by passed this correctly, return null for all user info in the api response. How do we test if this works with staging without merging?Right now, the request to ns to get user information remains the same as what's in this code, so we know that it's successfully getting user info. on staging.
What are the relevant tickets?
#5408