I'm missing something in my code and I would like to know where is the problem. I want to test if my API responses can handle exceptions but they only return 500 if the user is unauthorized.
I did look at this topic, in my case I would get a 401 error when I call this route.
Controller
public function index()
{
try{
return response()->json(Product::orderByDesc('updated_at')->get(), 200);
} catch (\Exception $e) {
throw new HttpException(401, $e->getMessage());
}
}
What should I do ?