【laravel】dingo api自定义异常格式

dinggo api 自定义异常格式

app/Pviders/AppServiceProviderregister方法加入.

1
2
3
4
5
6
7
8
9
10
11
12
\API::error(function (\Illuminate\Validation\ValidationException $exception){
$data =$exception->validator->getMessageBag();
$msg = collect($data)->first();
if(is_array($msg)){
$msg = $msg[0];
}
return response()->json(['message'=>$msg,'status_code'=>400], 200);
});
\API::error(function (\Dingo\Api\Exception\ValidationHttpException $exception){
$errors = $exception->getErrors();
return response()->json(['message'=>$errors->first(),'status_code'=>400], 200);
});

坚持原创技术分享,您的支持将鼓励我继续创作!
0%