1 | <?php |
||
24 | trait HandlesApiErrors |
||
25 | { |
||
26 | /** |
||
27 | * Checks if the exception extends from the package API exception. |
||
28 | * |
||
29 | * @param Exception $e |
||
30 | * @return bool |
||
31 | */ |
||
32 | protected function isApiError( Exception $e ):bool |
||
36 | |||
37 | /** |
||
38 | * Transforms and renders api responses. |
||
39 | * |
||
40 | * @param Exception $e |
||
41 | * @return JsonResponse |
||
42 | */ |
||
43 | protected function renderApiErrors( Exception $e ):JsonResponse |
||
51 | |||
52 | /** |
||
53 | * Checks if the application is currently in testing mode. |
||
54 | * |
||
55 | * @return bool |
||
56 | */ |
||
57 | protected function isRunningTests():bool |
||
61 | |||
62 | /** |
||
63 | * Renders readable responses for console, useful for testing. |
||
64 | * |
||
65 | * @param Exception $e |
||
66 | * @return void |
||
67 | */ |
||
68 | protected function renderTestErrors( Exception $e ) |
||
72 | |||
73 | /** |
||
74 | * Transform Laravel exceptions into API exceptions. |
||
75 | * |
||
76 | * @param Exception $e |
||
77 | * @return void |
||
78 | * @throws ResourceNotFoundException |
||
79 | * @throws UnauthorizedException |
||
80 | */ |
||
81 | protected function transformExceptions( Exception $e ) |
||
91 | |||
92 | /** |
||
93 | * Render an exception into an API response. |
||
94 | * |
||
95 | * @param ApiException $e |
||
96 | * @return JsonResponse |
||
97 | */ |
||
98 | protected function renderApiResponse( ApiException $e ):JsonResponse |
||
104 | |||
105 | /** |
||
106 | * Render an exception into an HTTP response for the console, used for debugging in test mode. |
||
107 | * |
||
108 | * @param Exception $e |
||
109 | * @return void |
||
110 | */ |
||
111 | protected function renderConsoleResponse( Exception $e ) |
||
115 | |||
116 | /** |
||
117 | * Render an exception to the console. |
||
118 | * |
||
119 | * |
||
120 | */ |
||
121 | abstract public function renderForConsole( $output, Exception $e ); |
||
122 | } |