@@ -75,12 +75,16 @@ public function showAction(Request $request, $exception, DebugLoggerInterface $l
7575 ));
7676 }
7777
78- $ format = $ this ->getFormat ($ request , $ request ->getRequestFormat ());
78+ try {
79+ $ format = $ this ->getFormat ($ request , $ request ->getRequestFormat ());
80+ } catch (\Exception $ e ) {
81+ $ format = null ;
82+ }
7983 if (null === $ format ) {
8084 $ message = 'No matching accepted Response format could be determined, while handling: ' ;
8185 $ message .= $ this ->getExceptionMessage ($ exception );
8286
83- return new Response ($ message , Codes::HTTP_NOT_ACCEPTABLE , $ exception ->getHeaders ());
87+ return $ this -> createPlainResponse ($ message , Codes::HTTP_NOT_ACCEPTABLE , $ exception ->getHeaders ());
8488 }
8589
8690 $ currentContent = $ this ->getAndCleanOutputBuffering ();
@@ -105,12 +109,28 @@ public function showAction(Request $request, $exception, DebugLoggerInterface $l
105109 } catch (\Exception $ e ) {
106110 $ message = 'An Exception was thrown while handling: ' ;
107111 $ message .= $ this ->getExceptionMessage ($ exception );
108- $ response = new Response ($ message , Codes::HTTP_INTERNAL_SERVER_ERROR , $ exception ->getHeaders ());
112+ $ response = $ this -> createPlainResponse ($ message , Codes::HTTP_INTERNAL_SERVER_ERROR , $ exception ->getHeaders ());
109113 }
110114
111115 return $ response ;
112116 }
113117
118+ /**
119+ * Returns a Response Object with content type text/plain.
120+ *
121+ * @param string $content
122+ * @param int $status
123+ * @param array $headers
124+ *
125+ * @return Response
126+ */
127+ private function createPlainResponse ($ content , $ status = 200 , $ headers = array ())
128+ {
129+ $ headers ['content-type ' ] = 'text/plain ' ;
130+
131+ return new Response ($ content , $ status , $ headers );
132+ }
133+
114134 /**
115135 * Gets and cleans any content that was already outputted.
116136 *
0 commit comments