In case of authentication failure (session-id expired, which does after 15minute of inactivity), the only way to get a new session id is to reauthenticate.
And, I have created a helper function to authenticate and could be called at:
$sessionID = TPPAPIHelper::getSessionID();
and my current code: looks like this:
$sessionID = session()->get('TPP_SESSION_ID');
try{
$response = Http::retry(3, 100)->asForm()->post(config('services.tpp.api_url').'/query.pl', [
'SessionID' => $sessionID,
//other params
])->throw();
$body = $response->body();
if(Str::contains($body, 'ERR: 102')){
//need to reauthenticate and call api again
}
}catch(\Exception $e){
}
So, in the above case: if I received this ERR: 102 I want to call TPPAPIHelper::getSessionID(); to get a new session id and execute this try block 1 more time, how could I do this correct way?