protected function errorResponse(Request $request, \Exception $exception): JsonResponse
    {
        if ($exception instanceof EntryNotFoundException || $exception instanceof SectionNotFoundException) {
            $statusCode = JsonResponse::HTTP_NOT_FOUND;
        } else {
            $statusCode = JsonResponse::HTTP_BAD_REQUEST;
        }
        return new JsonResponse([
            'error' => $exception->getMessage()
        ], $statusCode, $this->getDefaultResponseHeaders($request));
    }
protected function errorResponse(Request $request, \Exception $exception): JsonResponse
    {
        if ($exception instanceof EntryNotFoundException || $exception instanceof SectionNotFoundException) {
            $statusCode = JsonResponse::HTTP_NOT_FOUND;
        } else {
            $statusCode = JsonResponse::HTTP_BAD_REQUEST;
        }
        return new JsonResponse([
            'error' => $exception->getMessage()
        ], $statusCode, $this->getDefaultResponseHeaders($request));
    }
protected function errorResponse ( Request $ request , \ Exception $ exception ) : JsonResponse { if ( $ exception instanceof EntryNotFoundException || $ exception instanceof SectionNotFoundException ) { $ statusCode = JsonResponse :: HTTP_NOT_FOUND ; } else { $ statusCode = JsonResponse :: HTTP_BAD_REQUEST ; } return new JsonResponse ( [ 'error' => $ exception -> getMessage ( ) ] , $ statusCode , $ this -> getDefaultResponseHeaders ( $ request ) ) ; }
Build a JSON response to return when an exception occurs.
@param Request $request
@param \Exception $exception
@return JsonResponse
Build a JSON response to return when an exception occurs .