2
我有一些麻煩讓這個中間件在Laravel工作。我正在使用Tymon的JWT來檢查一個標記是否有效,但是當我用Postman測試時,我根本沒有得到任何響應,而不是我設置的HTTP 4xx錯誤。郵差顯示沒有響應Laravel中間件異常
public function handle($request, Closure $next, $guard = null)
{
try {
JWTAuth::parseToken()->authenticate();
} catch (TokenExpiredException $e) { //Token Expired
return response('Token Expired', 440);
} catch (TokenInvalidException $e) { //Token Invalid
return response('Token Invalid', 401);
} catch (JWTException $e) {
echo("TEST");
return response('Token Exception', 499);
} catch (TokenBlacklistedException $e) { //Token Blacklisted
return response('Token Blacklisted', 403);
}
return $next($request);
}
當我嘗試在郵遞員調用的標題中使用沒有標記時,它告訴我沒有來自服務器的響應。
Could not get any response
There was an error connecting to api.website.dev/test.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Client certificates are required for this server:
Fix this by adding client certificates in Settings > Certificates
Request timeout:
Change request timeout in Settings > General
的例外似乎被觸發,但我只能從服務器獲取的反應,當我把東西像一個echo語句如上面的代碼所示。 我一直在我的代碼的其他部分以及我無法創建排隊的作業,並且郵差說服務器沒有響應相同的Could not get any response
消息的這個問題。
這是Laravel的問題還是我做錯了什麼? 預先感謝您的幫助!
下次發佈您正在使用的郵差版本時會有幫助,以及常規的'curl'響應是什麼 - 以防萬一它是[this](https://github.com/postmanlabs/postman) -app-support/issues/2214)或[this](https://github.com/postmanlabs/postman-app-support/issues/1041)。因爲您也在爲您的測試用例發送不尋常的(非標準)HTTP響應代碼,這也可能會導致測試工具出現問題,因此最好使用404等標準響應進行測試。 – Leith
這很可能是由於自定義爲Paw編寫的HTTP lib,可以讀取完整的錯誤代碼和狀態消息,大多數其他庫不提供此信息請參閱https://paw.cloud/docs/advanced/http-libraries –