我想在我的postman中處理500內部服務器錯誤作為JSON回應,請幫助我。
我在Exception/Handler.php中有這樣的代碼,我不知道如何在POSTMAN中處理一個回傳JSON回應的500內部服務器錯誤,
。 $this-> renderable(function (HttpException $e, $request) {
if($request->is('api/*')){
return response()->json(['message'=> $e-> getMessage(),'code'=> $e-> getStatusCode()])。
}});
uj5u.com熱心網友回復:
這是Laravel檔案中的一個例子:
public function register()
{
$this-> renderable(function (InvalidOrderException $e, $request) {
return response()->view('errors.invalid-order', [], 500)。)
});
}
https://laravel.com/docs/8.x/errors
uj5u.com熱心網友回復:
你可以很容易地在你的控制器中使用try/catch,
。例如,這個代碼看起來像這樣。 并在回應中回傳你想要的任何狀態,而不是服務器錯誤系列代碼。
use IlluminateHttpResponse;
try {
//代碼
//
} catch (Exception $e) {
return response()->json(['message' => $e-> getMessage()], Response::HTTP_NOT_FOUND);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/324220.html
標籤:
