webman返回json響應(yīng)頭錯(cuò)誤
// 參數(shù)驗(yàn)證錯(cuò)誤
if ($exception instanceof ValidateException) {
return json($exception->getError(), 422);
}
if($exception instanceof ApiException){
//加以下兩行也沒有用。響應(yīng)頭還是 text/html; charset=UTF-8
//$response = response();
// $response->header('Content-Type', 'application/json');
return json(['code'=>$exception->getCode(),'msg'=>$exception->getMessage()]);
}
// 請(qǐng)求異常
if ($exception instanceof HttpException && request()->isAjax()) {
return response($exception->getMessage(), $exception->getStatusCode());
}
return parent::render($request, $exception);
}
1個(gè)回答
年代過于久遠(yuǎn),無法發(fā)表回答