我使用FOERestBundle和類View。當我確認實體我有這樣的對象錯誤,這就是:FOSRestBundle返回對象錯誤
[
{
"property_path": "main_skill",
"message": "This value should not be blank."
},
{
"property_path": "type",
"message": "This value should not be blank."
},
{
"property_path": "description",
"message": "This value should not be blank."
}
]
我需要返回的對象錯誤,當這樣的
[
{
"property_path": "main_skill",
"message": "This value should not be blank."
},
]
用戶不是有效的安全令牌現在我有純文本。這是我的終點
/**
* Update existing Bit from the submitted data.
*
* @ApiDoc(
* resource = true,
* description = "Update single Bit",
* parameters={
* {"name"="status", "dataType"="string", "required"=false, "description"="status for bit"},
* {"name"="text", "dataType"="string", "required"=true, "description"="text for rejected"},
* {"name"="token", "dataType"="string", "required"=true, "description"="is equally md5('email'.secret_word)"}
* },
* statusCodes = {
* 200 = "Bit successful update",
* 400 = "Secret token is not valid"
* },
* section="Bit"
*)
* @RestView()
*
* @param Request $request
* @param string $id
*
* @return View
*/
public function putBitAction(Request $request, $id)
{
$manager = $this->getDoctrine()->getManager();
$token = $this->get('request')->request->get('token');
$user = $this->getDoctrine()->getRepository('MyBundle:Users')->findOneBySecuritytoken($token);
$bit = $manager->getRepository('MyBundle:Bit')->find($id);
$view = View::create();
if (!empty($user) && !empty($bit) && !empty($token)) {
*some logic
$view = $this->view($bit, 200);
return $this->handleView($view);
}
} else {
$view = $this->view('Secret token is not valid', 400);
return $this->handleView($view);
}
}
現在我有明文
Response Body [Raw]
"Secret token is not valid"
這是返回的對象錯誤驗證,這是確定的
[
{
"property_path": "main_skill",
"message": "This value should not be blank."
},
{
"property_path": "type",
"message": "This value should not be blank."
},
{
"property_path": "description",
"message": "This value should not be blank."
}
]
如何返回的自定義錯誤,如對象不是純文本?
我已經把邏輯。我有一個prod枝: exception_controller:ArtelProfileBundle:Exception:showException this action = return $ this-> redirect($ this-> generateUrl('login_route'));和BadRequestHttpException,NotFoundHttpException不會在prod中返回prod返回login_page,而是查看prod工作得很好 –