It's possible that the response is empty because the restLogin() function is not returning anything. Try modifying the restLogin() function to return the response from getJobs() like this:
public function restLogin($function, $request = null)
{
//code for API auth stuff...
if ( $loginResponse->successful() ) {
// save the latest auth token and then re-run the original API call again...
//...
return $this->getJobs(); // return the response from getJobs()
}
}
Also, make sure to return the response from restLogin() when it's called from getJobs():
public function getJobs()
{
// code to get tokens and construct api url
//...
$jobsResponse = Http::withHeaders([
'Content-Type' => 'application/json',
'BhRestToken' => $rest_token,
])->get($jobs_url);
Log::info('get jobs run');
if ( $jobsResponse->successful() ) {
$jobsResponseArray = $jobsResponse->json();
Log::info('get jobs run successful');
Log::info($jobsResponseArray);
$response = response()->json([
'data' => $jobsResponseArray
], 200);
return $response;
} else {
return $this->restLogin('getJobs'); // return the response from restLogin()
}
}
This should ensure that the response from getJobs() is returned all the way up the call stack, even when restLogin() is called.