fix: answer null instead of 500 when the export marker is missing
This commit is contained in:
1 parent
8a6ce7606f
commit
c2c55bc8b2
4 files changed
+83
-15
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\BusProNet\Model\XmlExportInfo;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@@ -16,23 +17,15 @@ class LastUpdateController extends AbstractController
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A missing or unreadable marker answers `{"timestamp": null}`, never a 500: consumers
|
||||
* poll this for change detection and treat null as "unknown".
|
||||
*/
|
||||
#[Route(path: '/last-update', name: 'api_last_update', methods: ['GET'])]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
if (false === $this->xmlExport->has('uebertragung.info')) {
|
||||
$lastUploadAt = null;
|
||||
} else {
|
||||
$file = $this->xmlExport->read('uebertragung.info');
|
||||
$lines = explode("\n", $file);
|
||||
$line = trim($lines[0]);
|
||||
$info = XmlExportInfo::fromStorage($this->xmlExport);
|
||||
|
||||
if (true === empty($line)) {
|
||||
$lastUploadAt = null;
|
||||
} else {
|
||||
$lastUploadAt = \DateTime::createFromFormat('d.m.Y H:i:s', $line);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->json(['timestamp' => $lastUploadAt->format('Y-m-d H:i:s')]);
|
||||
return $this->json(['timestamp' => $info?->lastTransfer->format('Y-m-d H:i:s')]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user