aboutsummaryrefslogtreecommitdiffhomepage
path: root/infrastructure/Exceptions/Formatters/ExceptionFormatter.php
blob: 920ea693e4852cffc97d01c1db1b395a866e5219 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace Infrastructure\Exceptions\Formatters;

use Exception;
use Illuminate\Http\JsonResponse;
use Optimus\Heimdal\Formatters\BaseFormatter;

class ExceptionFormatter extends BaseFormatter
{
    public function format(JsonResponse $response, Exception $e, array $reporterResponses)
    {
        $response->setStatusCode(500);
        $data = $response->getData(true);

        if ($this->debug) {
            $data = array_merge($data, [
                'code' => $e->getCode(),
                'message' => $e->getMessage(),
                'exception' => (string)$e,
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        } else {
            $data['message'] = $e->getMessage();
        }

        $response->setData($data);
    }
}