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;
  }