File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
src/Illuminate/Foundation/Exceptions Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -373,6 +373,8 @@ protected function prepareException(Throwable $e)
373373 $ e = new HttpException (419 , $ e ->getMessage (), $ e );
374374 } elseif ($ e instanceof SuspiciousOperationException) {
375375 $ e = new NotFoundHttpException ('Bad hostname provided. ' , $ e );
376+ } elseif ($ e instanceof RecordsNotFoundException) {
377+ $ e = new NotFoundHttpException ('Not found. ' , $ e );
376378 }
377379
378380 return $ e ;
Original file line number Diff line number Diff line change 88use Illuminate \Contracts \Routing \ResponseFactory as ResponseFactoryContract ;
99use Illuminate \Contracts \Support \Responsable ;
1010use Illuminate \Contracts \View \Factory ;
11+ use Illuminate \Database \RecordsNotFoundException ;
1112use Illuminate \Foundation \Exceptions \Handler ;
1213use Illuminate \Http \RedirectResponse ;
1314use Illuminate \Http \Request ;
@@ -235,6 +236,23 @@ public function testSuspiciousOperationReturns404WithoutReporting()
235236
236237 $ this ->handler ->report (new SuspiciousOperationException ('Invalid method override "__CONSTRUCT" ' ));
237238 }
239+
240+ public function testRecordsNotFoundReturns404WithoutReporting ()
241+ {
242+ $ this ->config ->shouldReceive ('get ' )->with ('app.debug ' , null )->once ()->andReturn (true );
243+ $ this ->request ->shouldReceive ('expectsJson ' )->once ()->andReturn (true );
244+
245+ $ response = $ this ->handler ->render ($ this ->request , new RecordsNotFoundException ());
246+
247+ $ this ->assertEquals (404 , $ response ->getStatusCode ());
248+ $ this ->assertStringContainsString ('"message": "Not found." ' , $ response ->getContent ());
249+
250+ $ logger = m::mock (LoggerInterface::class);
251+ $ this ->container ->instance (LoggerInterface::class, $ logger );
252+ $ logger ->shouldNotReceive ('error ' );
253+
254+ $ this ->handler ->report (new RecordsNotFoundException ());
255+ }
238256}
239257
240258class CustomException extends Exception
You can’t perform that action at this time.
0 commit comments