Answer the question
In order to leave comments, you need to log in
Why is further execution of the script in Yii being killed if an error message is received in the response from guzzle in the header?
in theory, if an error occurs, it should simply be written to the file, return false and go to the next method
[response_b: ] => {"errors":[{"error":"Authentication error: Incorrect or expired access key","code":1056 ,"moreInfo":" https://dev.moysklad.ru/doc/api/remap/1.2/#mojskla... "}]}
// for test получить сотрудников
public function getEmployee()
{
try {
$res = $this->client->get("entity/employee");
} catch (BadResponseException $e) {
$this->logError($e);
}
if (!$res) return false;
$res = json_decode($res->getBody()->getContents());
return $res ?? false;
}
private function logError(BadResponseException $e)
{
$error = [
'request_h: ' => $e->getRequest()->getHeaders(),
'request_b: ' => $e->getRequest()->getBody()->getContents(),
'response_c: ' => $e->getResponse()->getStatusCode(),
'response_h: ' => $e->getResponse()->getHeaders(),
'response_b: ' => $e->getResponse()->getBody()->getContents(),
];
\Yii::error(print_r($error, 1), 'moysklad');
// \Yii::warning(print_r($error, 1), 'moysklad');
}
public function updateInvoiceStatusAllAccounts($uid, $status)
{
$moySklad3 = new \common\components\MoySklad\MoySklad();
$msAccounts = $moySklad3->getMsAccountTokens();
if (!$msAccounts) return false;
foreach ($msAccounts as $k => $account) {
$moySklad3 = new \common\components\MoySklad\MoySklad($account->token);
// токен валидный?
$employee = $moySklad3->getEmployee();
if (!$employee) continue;
$res = $moySklad3->passStatusInvoice($uid, $status);
if ($res) {
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question