поля? При валидации через реквест модел.
final class ExceptionMiddleware implements MiddlewareInterface { public function __construct(private DataResponseFactoryInterface $dataResponseFactory) {} public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { try { return $handler->handle($request); } catch (RequestValidationException $e) { $validationErrors = $e->getErrors(); $firstField = key($validationErrors); $errorMessage = $firstField . ': ' . $validationErrors[$firstField][0]; return $this->dataResponseFactory->createResponse(['message' => $errorMessage], Status::BAD_REQUEST); } } }
Обсуждают сегодня