ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Whoops\Handler\JsonResponseHandler Class Reference

Catches an exception and converts it to a JSON response. More...

+ Inheritance diagram for Whoops\Handler\JsonResponseHandler:
+ Collaboration diagram for Whoops\Handler\JsonResponseHandler:

Public Member Functions

 setJsonApi ($jsonApi=false)
 Returns errors[[]] instead of error[] to be in compliance with the json:api spec. More...
 
 addTraceToOutput ($returnFrames=null)
 
 handle ()
 
 contentType ()
 
- Public Member Functions inherited from Whoops\Handler\Handler
 setRun (RunInterface $run)
 
 setInspector (Inspector $inspector)
 
 setException ($exception)
 
 handle ()
 
 setRun (RunInterface $run)
 
 setException ($exception)
 
 setInspector (Inspector $inspector)
 

Private Attributes

 $returnFrames = false
 
 $jsonApi = false
 

Additional Inherited Members

- Data Fields inherited from Whoops\Handler\Handler
const DONE = 0x10
 
const LAST_HANDLER = 0x20
 The Handler has handled the Throwable in some way, and wishes to skip any other Handler. More...
 
const QUIT = 0x30
 The Handler has handled the Throwable in some way, and wishes to quit/stop execution. More...
 
- Protected Member Functions inherited from Whoops\Handler\Handler
 getRun ()
 
 getInspector ()
 
 getException ()
 

Detailed Description

Catches an exception and converts it to a JSON response.

Additionally can also return exception frames for consumption by an API.

Definition at line 16 of file JsonResponseHandler.php.

Member Function Documentation

◆ addTraceToOutput()

Whoops\Handler\JsonResponseHandler::addTraceToOutput (   $returnFrames = null)
Parameters
bool | null$returnFrames
Returns
bool|$this

Definition at line 43 of file JsonResponseHandler.php.

44 {
45 if (func_num_args() == 0) {
47 }
48
49 $this->returnFrames = (bool) $returnFrames;
50 return $this;
51 }

References Whoops\Handler\JsonResponseHandler\$returnFrames.

Referenced by Whoops\Handler\JsonResponseHandler\handle().

+ Here is the caller graph for this function:

◆ contentType()

Whoops\Handler\JsonResponseHandler::contentType ( )
Returns
string

Definition at line 84 of file JsonResponseHandler.php.

85 {
86 return 'application/json';
87 }

◆ handle()

Whoops\Handler\JsonResponseHandler::handle ( )
Returns
int

Implements Whoops\Handler\HandlerInterface.

Definition at line 56 of file JsonResponseHandler.php.

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 }
const QUIT
The Handler has handled the Throwable in some way, and wishes to quit/stop execution.
Definition: Handler.php:31
$response

References $response, Whoops\Handler\JsonResponseHandler\addTraceToOutput(), Whoops\Handler\Handler\getInspector(), and Whoops\Handler\Handler\QUIT.

+ Here is the call graph for this function:

◆ setJsonApi()

Whoops\Handler\JsonResponseHandler::setJsonApi (   $jsonApi = false)

Returns errors[[]] instead of error[] to be in compliance with the json:api spec.

Parameters
bool$jsonApiDefault is false
Returns
$this

Definition at line 33 of file JsonResponseHandler.php.

34 {
35 $this->jsonApi = (bool) $jsonApi;
36 return $this;
37 }

References Whoops\Handler\JsonResponseHandler\$jsonApi.

Field Documentation

◆ $jsonApi

Whoops\Handler\JsonResponseHandler::$jsonApi = false
private

◆ $returnFrames

Whoops\Handler\JsonResponseHandler::$returnFrames = false
private

The documentation for this class was generated from the following file: