src/Support/Concerns/BuildsErrorResponses.php
public function buildErrorResponse(\Exception $e)
  {
    $response = [ 
        'type' => get_class($e),
        'code' => $e->getCode(),
        'message' => $e->getMessage(),
        'data' => [
            'status' => 500
        ]
    ];

    if ($e instanceof ModelNotFoundException) {
        $response['data']['status'] = 404;
    }

    if ($e instanceof HttpException) {
        $response['data']['status'] = $e->getStatusCode();
    }

    if ($e instanceof ValidationException) {
        $response['data']['errors'] = $e->messages();
    }

    if ($this->isDebugMode()) {
        $response['line'] = $e->getLine();
        $response['file'] = $e->getFile();
        $response['trace'] = $e->getTraceAsString();
    }

    return $response;
  }
public function buildErrorResponse(\Exception $e)
  {
    $response = [ 
        'type' => get_class($e),
        'code' => $e->getCode(),
        'message' => $e->getMessage(),
        'data' => [
            'status' => 500
        ]
    ];

    if ($e instanceof ModelNotFoundException) {
        $response['data']['status'] = 404;
    }

    if ($e instanceof HttpException) {
        $response['data']['status'] = $e->getStatusCode();
    }

    if ($e instanceof ValidationException) {
        $response['data']['errors'] = $e->messages();
    }

    if ($this->isDebugMode()) {
        $response['line'] = $e->getLine();
        $response['file'] = $e->getFile();
        $response['trace'] = $e->getTraceAsString();
    }

    return $response;
  }
public function buildErrorResponse ( \ Exception $ e ) { $ response = [ 'type' => get_class ( $ e ) , 'code' => $ e -> getCode ( ) , 'message' => $ e -> getMessage ( ) , 'data' => [ 'status' => 500 ] ] ; if ( $ e instanceof ModelNotFoundException ) { $ response [ 'data' ] [ 'status' ] = 404 ; } if ( $ e instanceof HttpException ) { $ response [ 'data' ] [ 'status' ] = $ e -> getStatusCode ( ) ; } if ( $ e instanceof ValidationException ) { $ response [ 'data' ] [ 'errors' ] = $ e -> messages ( ) ; } if ( $ this -> isDebugMode ( ) ) { $ response [ 'line' ] = $ e -> getLine ( ) ; $ response [ 'file' ] = $ e -> getFile ( ) ; $ response [ 'trace' ] = $ e -> getTraceAsString ( ) ; } return $ response ; }
Given an Exception, build a data package suitable for reporting
the error to the client.
@param Exception The exception
@return array
Given an Exception build a data package suitable for reporting the error to the client .