stopPropagation(); /** @var \Hyperf\Validation\ValidationException $throwable */ $keys = $throwable->validator->errors()->keys(); if (count($keys) > 0) { $msg = $keys[0] . str_replace("validation", "", $throwable->validator->errors()->first($keys[0])); } else { $msg = $throwable->validator->errors()->first(); } if (!$response->hasHeader('content-type')) { $response = $response->withAddedHeader('content-type', 'application/json; charset=utf-8'); } return $response->withStatus(200)->withBody(new SwooleStream(json_encode(['code'=>1,'msg'=>$msg]))); } /** * 验证之后 * @param Throwable $throwable * @return bool */ public function isValid(Throwable $throwable): bool { return $throwable instanceof ValidationException; } }