wrap get item with try catch
This commit is contained in:
parent
826bc13956
commit
7cdd4645bd
@ -5,6 +5,9 @@ namespace App\Http\Controllers;
|
||||
use App\Data\ItemsCollection;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class ItemController extends Controller
|
||||
{
|
||||
@ -35,8 +38,16 @@ class ItemController extends Controller
|
||||
*/
|
||||
public function getItem(string $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return response()->json([
|
||||
'item' => $this->itemsCollection->getItemById($id),
|
||||
]);
|
||||
} catch (Throwable $exception) {
|
||||
Log::error($exception->getMessage());
|
||||
Log::error($exception->getTraceAsString());
|
||||
return response()->json([
|
||||
'item' => [],
|
||||
], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user