Open new123-ui opened 1 month ago
protected function buildResponse(): Response
{
$bodyKey = array_keys($this->config['body']);
$bodyValue = array_values($this->config['body']);
$responseBody = [
$bodyKey[0] ?? 'code' => $this->setCode($bodyValue, $this->errorCode), // 自定义异常code码
$bodyKey[1] ?? 'message' => $this->errorMessage,
$bodyKey[2] ?? 'data' => $this->responseData,
];
$header = array_merge(['Content-Type' => 'application/json;charset=utf-8'], $this->header);
return new Response($this->statusCode, $header, json_encode($responseBody));
}
private function setCode($bodyValue, $errorCode)
{
if($errorCode > 0){
return $errorCode;
}
return $bodyValue[0] ?? 0;
}
欢迎提价PR哈
不好意思,最近在忙,家里的网络不行,好像还没有提交上,稍微等一下,我换个姿势再来提交一下
提交了
希望可以实现自定义配置返回code值,不是配置statusCode,而不是在app里面配置的固定的,代码如下 throw new BadRequestHttpException('帖子未找到,无法操作' , [ 'errorCode' => ApiSignExceptionCode::ARTICLE_NOT_FOUND, ]); 现阶段操作修改的逻辑为![image](https://github.com/Tinywan/webman-exception/assets/74286077/2e779183-6fd3-459a-bae3-d5c352090092)