Closed miken32 closed 8 months ago
Also worth noting that since PHP 7.3, JSON functions can be passed the JSON_THROW_ON_ERROR
flag so a JsonException
can be thrown automatically. This could be caught by your code and handled appropriately.
🤔 Looking at the stack trace, it looks like this error was encountered when trying to create a conversation within Help Scout. The extract()
that supplies json_encode()
is strongly typed to return an array
so it seems like a failure here and the other entities within Conversation::extract()
also use the entity's extract()
methods. It's unclear to me at the moment what could have caused such an error and we'd need some more details about how the convo was being created to understand what's going on.
That being said, you are correct that we should throw error if json can't be encoded.
Nothing too interesting about the conversation creation:
$customer = (new Customer())->addEmail($email);
$thread = (new CustomerThread())
->setText($body)
->setCustomer($customer);
$convo = (new Conversation())
->setSubject($subject)
->setPreview($body)
->setStatus(Status::ACTIVE)
->setType("email")
->addThread($thread)
->setCustomer($customer);
$convo->setMailboxId($mbox);
$convo_id = $this->helpscout->conversations()->create($convo);
A couple of custom fields added as well, but nothing too complicated. Whatever was returned by Conversation::extract()
couldn't be converted for some reason. This is the same code that's been used for hundreds of ticket creations and this is the first we've seen of this error.
v3.5.2 has been tagged with changes that'll throw an exception in that scenario. If you're able to update to this version, we can get a little more clarity as to what the underlying issue is next time this occurs.
Closing this issue due to inactivity. Please feel free to reopen if needed!
The return type for this method is declared as
string
but in case of an errorjson_encode()
will return false. The return type should be updated at the very least, or an exception thrown with contents ofjson_last_error_msg()
included.I came across this error recently, though I have no record of the arguments involved or why the Conversation object I passed couldn't be encoded.