public function it_can_handle_exception_during_request(RequestInterface $request) { $path = '/path/to/'; $request->offsetGet('path')->willReturn($path); $request->getAcceptContentType()->willReturn('*/*'); $this->fileRepository->getDirectoriesInPath($path)->willThrow(new \RuntimeException()); $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request); }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $path = $request['path']; $directories = $this->fileRepository->getDirectoriesInPath($path); $fileNames = $this->fileRepository->getFileNamesInPath($path); return new Response(self::MESSAGE, ['data' => ['path' => $path, 'directories' => $directories, 'files' => $fileNames]], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during GetDirectoryListingHandler.', new ServerErrorResponse([], $request)); } }