Return 404 if user not found

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-12-17 15:16:03 +01:00
parent dfb70cc5ce
commit 4c907c8ba5
2 changed files with 6 additions and 3 deletions
+4 -2
View File
@@ -3,11 +3,11 @@
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use App\Services\GetRole;
use App\Services\UserService;
use Propaganistas\LaravelPhone\PhoneNumber;
@@ -83,7 +83,9 @@ class UserController extends Controller
try {
return response()->json(UserService::getData($id));
} catch(\Exception $e) {
} catch (ModelNotFoundException $e) {
return response()->json(['message' => 'Utilisateur non trouvé'], 404);
} catch (\Exception $e) {
Log::info($e->getMessage());
return response()->json(['message' => "Server error"], 500);
}