| Conditions | 6 |
| Paths | 1 |
| Total Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function run($factory) |
||
| 16 | { |
||
| 17 | $factory->macro('error', |
||
| 18 | /** |
||
| 19 | * Return a new error JSON response from the application. |
||
| 20 | * Called like: response()->error(...) |
||
| 21 | * |
||
| 22 | * @param array $errors |
||
| 23 | * @param string $message |
||
| 24 | * @param int $status |
||
| 25 | * @param array $headers |
||
| 26 | * @param array $debugData |
||
| 27 | * @return JsonResponse |
||
| 28 | */ |
||
| 29 | function ( |
||
| 30 | $errors = [], |
||
| 31 | $message = '', |
||
| 32 | $status = HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
||
| 33 | array $headers = [], |
||
| 34 | $debugData = [] |
||
| 35 | ) use ($factory) { |
||
| 36 | $response = [ |
||
| 37 | 'success' => false, |
||
| 38 | 'message' => !empty($message) ? $message : 'Server error', |
||
| 39 | 'status' => !empty($status) ? $status : HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
||
| 40 | ]; |
||
| 41 | |||
| 42 | if (!empty($errors)) { |
||
| 43 | $response['errors'] = $errors; |
||
| 44 | } |
||
| 45 | |||
| 46 | if (!empty($debugData) && config('app.debug')) { |
||
| 47 | $response['debug'] = $debugData; |
||
| 48 | } |
||
| 49 | |||
| 50 | return $factory->json($response, $response['status'], $headers); |
||
| 51 | }); |
||
| 52 | } |
||
| 53 | } |
||
| 54 |