Mejor manejo de errores

This commit is contained in:
Alejandro Tasistro 2025-08-03 12:30:55 -03:00
parent e61c3f6d4b
commit 9cc82a9171

View file

@ -11,7 +11,9 @@ use App\Http\Resources\GrupoDeCompraResource;
use App\Producto;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use League\Csv\CannotInsertRecord;
use League\Csv\Exception;
use League\Csv\InvalidArgument;
use Mpdf\MpdfException;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
@ -31,7 +33,7 @@ class ComisionesController
{
try {
PedidosExportHelper::pedidosBarriales();
} catch (Exception $e) {
} catch (CannotInsertRecord|InvalidArgument|Exception $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
$pattern = storage_path('csv/exports/pedidos-por-barrio-*.csv');
@ -48,7 +50,7 @@ class ComisionesController
{
try {
PedidosExportHelper::pedidosDeOllas();
} catch (Exception $e) {
} catch (CannotInsertRecord|InvalidArgument|Exception $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
$pattern = storage_path('csv/exports/pedidos-de-ollas-*.csv');
@ -61,9 +63,13 @@ class ComisionesController
return response()->download($files[0]);
}
public function descargarNotas(): BinaryFileResponse
public function descargarNotas()
{
try {
Producto::planillaNotas();
} catch (CannotInsertRecord|InvalidArgument $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
$pattern = storage_path('csv/exports/notas-por-barrio-*.csv');
$files = glob($pattern);