ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
JsonResponseHandler.php
Go to the documentation of this file.
1 <?php
7 namespace Whoops\Handler;
8 
10 
17 {
21  private $returnFrames = false;
22 
26  private $jsonApi = false;
27 
33  public function setJsonApi($jsonApi = false)
34  {
35  $this->jsonApi = (bool) $jsonApi;
36  return $this;
37  }
38 
43  public function addTraceToOutput($returnFrames = null)
44  {
45  if (func_num_args() == 0) {
46  return $this->returnFrames;
47  }
48 
49  $this->returnFrames = (bool) $returnFrames;
50  return $this;
51  }
52 
56  public function handle()
57  {
58  if ($this->jsonApi === true) {
59  $response = [
60  'errors' => [
61  Formatter::formatExceptionAsDataArray(
62  $this->getInspector(),
63  $this->addTraceToOutput()
64  ),
65  ]
66  ];
67  } else {
68  $response = [
69  'error' => Formatter::formatExceptionAsDataArray(
70  $this->getInspector(),
71  $this->addTraceToOutput()
72  ),
73  ];
74  }
75 
76  echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);
77 
78  return Handler::QUIT;
79  }
80 
84  public function contentType()
85  {
86  return 'application/json';
87  }
88 }
Whoops - php errors for cool kids.
setJsonApi($jsonApi=false)
Returns errors[[]] instead of error[] to be in compliance with the json:api spec. ...
Catches an exception and converts it to a JSON response.
const QUIT
The Handler has handled the Throwable in some way, and wishes to quit/stop execution.
Definition: Handler.php:31
Abstract implementation of a Handler.
Definition: Handler.php:15
$response